bug #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 #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 | #20878
| License       | MIT

This should fix #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
This commit is contained in:
Fabien Potencier 2016-12-13 09:25:01 +01:00
commit 60f74845af

View File

@ -93,7 +93,7 @@ class PhpFilesAdapter extends AbstractAdapter
$ok = true;
$data = array($lifetime ? time() + $lifetime : PHP_INT_MAX, '');
foreach ($values as $id => $value) {
foreach ($values as $key => $value) {
if (null === $value || is_object($value)) {
$value = serialize($value);
} elseif (is_array($value)) {
@ -109,13 +109,16 @@ class PhpFilesAdapter extends AbstractAdapter
$value = serialize($value);
}
} elseif (!is_scalar($value)) {
throw new InvalidArgumentException(sprintf('Value of type "%s" is not serializable', $key, gettype($value)));
throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, gettype($value)));
}
$data[1] = $value;
$file = $this->getFile($id, true);
$file = $this->getFile($key, true);
$ok = $this->write($file, '<?php return '.var_export($data, true).';') && $ok;
@opcache_compile_file($file);
if ('cli' !== PHP_SAPI || ini_get('opcache.enable_cli')) {
@opcache_compile_file($file);
}
}
return $ok;