PHP 7.2.0 Release Candidate 4 Released


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

opcache_resetRé-initialise le contenu du cache opcode


boolean opcache_reset ( void )

Cette fonction ré-initialise le cache opcode dans sa globalité. Après l'appel à la fonction opcache_reset(), tous les scripts seront rechargés et ré-analysés lors de leurs prochains appels.

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

Retourne TRUE si le cache opcode a été ré-initialisé, ou FALSE si le cache opcode est désactivé.

Voir aussi

add a note add a note

User Contributed Notes 4 notes

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.
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.
fbgolly at gmail dot com
2 months ago
My workaround to clear cache via CLI is create a bash script like this:

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

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.
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

File b.php
include 'constants.php';

File constants.php
('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