Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does PHP's opcache re-parse a file?

Tags:

php

opcache

Just what the subject says - when does PHP's opcache re-parse a file? Is it based on file timestamp, or file hash or what?

Edit: If my question is not clear then I'll try again:) Say a file "xyz.php" is already in OPCache. Now I modify the file - and it obviously has to be parsed again and updated in the cache. How PHP knows it should do it?

like image 729
konrados Avatar asked Apr 02 '17 16:04

konrados


1 Answers

It is based on your opcache configuration in your php.ini file.

opcache.revalidate_freq - Basically put, how often (in seconds) should the code cache expire and check if your code has changed. 0 means it checks your PHP code every single request (which adds lots of stat syscalls). Set it to 0 in your development environment. Production doesn't matter because of the next setting.

opcache.validate_timestamps - When this is enabled, PHP will check the file timestamp per your opcache.revalidate_freq value.

When it's disabled, opcache.revaliate_freq is ignored and PHP files are NEVER checked for updated code. So, if you modify your code, the changes won't actually run until you restart or reload PHP.

like image 195
Hyder B. Avatar answered Oct 13 '22 00:10

Hyder B.