| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\OpcacheException; |
| 6 |
|
| 7 |
/** |
| 8 |
* This function compiles a PHP script and adds it to the opcode cache without |
| 9 |
* executing it. This can be used to prime the cache after a Web server |
| 10 |
* restart by pre-caching files that will be included in later requests. |
| 11 |
* |
| 12 |
* @param string $file The path to the PHP script to be compiled. |
| 13 |
* @throws OpcacheException |
| 14 |
* |
| 15 |
*/ |
| 16 |
function opcache_compile_file(string $file): void |
| 17 |
{ |
| 18 |
error_clear_last(); |
| 19 |
$result = \opcache_compile_file($file); |
| 20 |
if ($result === false) { |
| 21 |
throw OpcacheException::createFromPhpError(); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* This function returns state information about the cache instance |
| 28 |
* |
| 29 |
* @param bool $get_scripts Include script specific state information |
| 30 |
* @return array Returns an array of information, optionally containing script specific state information. |
| 31 |
* @throws OpcacheException |
| 32 |
* |
| 33 |
*/ |
| 34 |
function opcache_get_status(bool $get_scripts = true): array |
| 35 |
{ |
| 36 |
error_clear_last(); |
| 37 |
$result = \opcache_get_status($get_scripts); |
| 38 |
if ($result === false) { |
| 39 |
throw OpcacheException::createFromPhpError(); |
| 40 |
} |
| 41 |
return $result; |
| 42 |
} |
| 43 |
|