Skip to content

Commit ff8b0ad

Browse files
committed
opcache.file_cache_permissions
1 parent b53440a commit ff8b0ad

5 files changed

Lines changed: 40 additions & 4 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
opcache.file_cache_permissions
3+
--EXTENSIONS--
4+
opcache
5+
--SKIPIF--
6+
<?php
7+
$fileCache = sys_get_temp_dir() . '/9664b02e-6f64-42dd-b088-99f3dccc3422';
8+
@mkdir($fileCache, 0777, true);
9+
?>
10+
--INI--
11+
opcache.enable="1"
12+
opcache.enable_cli="1"
13+
opcache.file_cache="{TMP}/9664b02e-6f64-42dd-b088-99f3dccc3422"
14+
opcache.file_cache_only="1"
15+
opcache.file_update_protection="0"
16+
opcache.file_cache_permissions="0660"
17+
--FILE--
18+
<?php
19+
$fileCache = sys_get_temp_dir() . '/9664b02e-6f64-42dd-b088-99f3dccc3422';
20+
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fileCache, FilesystemIterator::SKIP_DOTS));
21+
foreach ($iterator as $splFileInfo) {
22+
if (!$splFileInfo->isFile()) {
23+
continue;
24+
}
25+
if (str_ends_with($splFileInfo->getPathname(), '.bin')) {
26+
var_dump(sprintf('%o', fileperms($splFileInfo->getPathname()) & 0o777));
27+
break;
28+
}
29+
}
30+
?>
31+
--EXPECT--
32+
string(3) "660"

ext/opcache/zend_accelerator_module.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
#include <time.h>
21-
#include <fcntl.h>
2221

2322
#include "php.h"
2423
#include "ZendAccelerator.h"
@@ -321,7 +320,7 @@ ZEND_INI_BEGIN()
321320
#endif
322321

323322
STD_PHP_INI_ENTRY("opcache.file_cache" , NULL , PHP_INI_SYSTEM, OnUpdateFileCache, accel_directives.file_cache, zend_accel_globals, accel_globals)
324-
STD_PHP_INI_ENTRY("opcache.file_cache_permissions", "384" /* S_IRUSR | S_IWUSR */, PHP_INI_SYSTEM, OnUpdateLong, accel_directives.file_cache_permissions, zend_accel_globals, accel_globals)
323+
STD_PHP_INI_ENTRY("opcache.file_cache_permissions", "0600", PHP_INI_SYSTEM, OnUpdateLong, accel_directives.file_cache_permissions, zend_accel_globals, accel_globals)
325324
STD_PHP_INI_BOOLEAN("opcache.file_cache_read_only" , "0" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.file_cache_read_only, zend_accel_globals, accel_globals)
326325
STD_PHP_INI_BOOLEAN("opcache.file_cache_only" , "0" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.file_cache_only, zend_accel_globals, accel_globals)
327326
STD_PHP_INI_BOOLEAN("opcache.file_cache_consistency_checks" , "1" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.file_cache_consistency_checks, zend_accel_globals, accel_globals)

ext/opcache/zend_file_cache.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,11 @@ int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
11791179
efree(filename);
11801180
return FAILURE;
11811181
}
1182+
#ifndef ZEND_WIN32
1183+
if (fchmod(fd, ZCG(accel_directives).file_cache_permissions) == -1) {
1184+
zend_accel_error(ACCEL_LOG_WARNING, "Unable to change opcache file permissions in %s: %s (%d)", filename, strerror(errno), errno);
1185+
}
1186+
#endif
11821187

11831188
if (zend_file_cache_flock(fd, LOCK_EX) != 0) {
11841189
close(fd);

php.ini-development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ ldap.max_links = -1
17781778
;opcache.file_cache=
17791779

17801780
; The permissions of the files cached.
1781-
;opcache.file_cache_permissions=384 (0o600)
1781+
;opcache.file_cache_permissions=0600
17821782

17831783
; Enables or disables read-only mode for the second level cache directory.
17841784
; It should improve performance for read-only containers,

php.ini-production

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ ldap.max_links = -1
17801780
;opcache.file_cache=
17811781

17821782
; The permissions of the files cached.
1783-
;opcache.file_cache_permissions=384 (0o600)
1783+
;opcache.file_cache_permissions=0600
17841784

17851785
; Enables or disables read-only mode for the second level cache directory.
17861786
; It should improve performance for read-only containers,

0 commit comments

Comments
 (0)