Skip to content

Commit 60f7484

Browse files
committed
bug symfony#20883 Don’t compile when Opcache is not enabled on CLI (ruudk)
This PR was squashed before being merged into the 3.2 branch (closes symfony#20883). Discussion ---------- Don’t compile when Opcache is not enabled on CLI | Q | A | ------------- | --- | Branch? | 3.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#20878 | License | MIT This should fix symfony#20878 "Zend OPcache seems to be disabled, can't compile file" when Opcache is enabled, but `opcache.enable_cli` is turned off. Commits ------- 5222643 Don’t compile when Opcache is not enabled on CLI
2 parents 0daa64f + 5222643 commit 60f7484

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function doSave(array $values, $lifetime)
9393
$ok = true;
9494
$data = array($lifetime ? time() + $lifetime : PHP_INT_MAX, '');
9595

96-
foreach ($values as $id => $value) {
96+
foreach ($values as $key => $value) {
9797
if (null === $value || is_object($value)) {
9898
$value = serialize($value);
9999
} elseif (is_array($value)) {
@@ -109,13 +109,16 @@ protected function doSave(array $values, $lifetime)
109109
$value = serialize($value);
110110
}
111111
} elseif (!is_scalar($value)) {
112-
throw new InvalidArgumentException(sprintf('Value of type "%s" is not serializable', $key, gettype($value)));
112+
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, gettype($value)));
113113
}
114114

115115
$data[1] = $value;
116-
$file = $this->getFile($id, true);
116+
$file = $this->getFile($key, true);
117117
$ok = $this->write($file, '<?php return '.var_export($data, true).';') && $ok;
118-
@opcache_compile_file($file);
118+
119+
if ('cli' !== PHP_SAPI || ini_get('opcache.enable_cli')) {
120+
@opcache_compile_file($file);
121+
}
119122
}
120123

121124
return $ok;

0 commit comments

Comments
 (0)