opcache_reset

(PHP 5 >= 5.5.0, PHP 7, PECL ZendOpcache >= 7.0.0)

opcache_reset重置字节码缓存的内容

说明

boolean opcache_reset ( void )

该函数将重置整个字节码缓存。 在调用 opcache_reset() 之后,所有的脚本将会重新载入并且在下次被点击的时候重新解析。

参数

此函数没有参数。

返回值

如果字节码缓存被重置成功,则返回 TRUE;如果字节码缓存被禁用,则返回 FALSE

参见

add a note add a note

User Contributed Notes 4 notes

up
20
Anonymous
2 years ago
It should be mentioned that opcache_reset() does not reset cache when executed via cli.
So `php -r "var_dump(opcache_reset());"` outputs "true" but doesn't clean cache. Make file, access it via http - and cache is clean.
up
6
mike
1 year ago
In some (most?) systems PHP's CLI has a separate opcode cache to the one used by the web server or PHP-FPM process, which means running opcache_reset() in the CLI won't reset the webserver/fpm opcode cache, and vice-versa.
up
0
fbgolly at gmail dot com
3 months ago
My workaround to clear cache via CLI is create a bash script like this:

#!/bin/bash
WEBDIR=/var/www/html/
RANDOM_NAME=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)
echo "<?php opcache_reset(); ?>" > ${WEBDIR}${RANDOM_NAME}.php
curl http://localhost/${RANDOM_NAME}.php
rm ${WEBDIR}${RANDOM_NAME}.php

put it in /usr/local/bin/opcache-clear and make it executable.
When I want to clear cache I simply run "opcache-clear" inside terminal.
up
-17
antoine dot vdsk at gmail dot com
2 years ago
For people who have difficulties with constants and opcache_reset().
If you include a file with constant and do an opcache_reset() in the same file, you'll probably have some error like :

"Notice: Constant already defined"

The trick is to call opcache_reset() in an isolated file, then include another file that include the file with constants.

File a.php
<?php
opcache_reset
();
include
'b.php'
?>

File b.php
<?php
include 'constants.php';
?>

File constants.php
<?php
define
('MY_CONST', 'abcdef');
?>

With this trick, the opcache will be reset in a.php and when b.php will be included, the constants will not be in cache anymore.
To Top