There was an online fault last night. The fault was alleviated after emergency processing and switching to disaster recovery. After the fault was solved, the fault was switched back to the official service. It was found that the PHP file update was invalid and took effect only after restarting FPM. The process of review and investigation is recorded below. Because the PHP file update did not take effect, I immediately suspected opcache. I took a look at php.ini online and found that opcache was indeed used and the detection interval was set to 60 seconds. Check last night’s log for updates"> The pitfall of opcache in detecting file updates.bd sapi cache. The Chinese translation of cache is cache. How to pronounce cache?-PHP Tutorial-php.cn

The pitfall of opcache in detecting file updates.bd sapi cache. The Chinese translation of cache is cache. How to pronounce cache?

WBOY
Release: 2016-07-29 08:52:55
Original
3009 people have browsed it

data-id="1190000004975909" data-licence="">

There was an online failure last night. After emergency processing and switching to disaster recovery, the failure was alleviated. After resolving the failure and switching back to the official service from disaster recovery, it was found that the PHP file update was invalid. After restarting FPM before it takes effect. The process of review and investigation is recorded below.

Because the PHP file update did not take effect, I immediately suspected opcache. I took a look at php.ini online and found that opcache was indeed used and the detection interval was set to 60 seconds. Looking at last night's log, the duration of the update not taking effect is much longer than 60 seconds, so this detection interval issue can be passed and we continue.

When I checked the updated files and the time in the log in the online environment, I suddenly found that the PHP file time did not correspond to the time in the log. I immediately asked the OP to confirm. The OP explained that this file was rolled back from the mv, so the file The time was not what I expected. I used the stat command to check, and sure enough, the modification time is a while earlier than the access time. Based on this clue, I speculate that opcache relies on the modification time of the PHP file as the detection condition for the file to be modified. The problem was reproduced offline and the pit was filled successfully!

The following summarizes some relevant knowledge points that were checked during the pit filling process

Loading opcache

When adding opcache in php.ini, you need to use zend_extension instead of extension, otherwise you will get the following WARNING

PHP Warning: PHP Startup: Invalid library (appears to be a Zend Extension, try loading using zend_extension=opcache.so from php.ini) in Unknown on line 0
Copy after login

Configure opcache

Use the following recommended settings to get better performance:

opcache.memory_c opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=1
Copy after login

There are two parameters involved this time

revalidate_freq, the default is 2
The period to check whether the script timestamp has been updated, in seconds. Setting it to 0 will cause OPcache to check for script updates for each request

validate_timestamps, the default is 1
If enabled, OPcache will check whether the script has been updated every seconds set by opcache.revalidate_freq. If this option is disabled, you must manually reset OPcache using the opcache_reset() or opcache_invalidate() functions, or restart the web server for file system changes to take effect.

System command and function stat

access time represents the last time we accessed the file
modify time represents the last time we modified the file
change time represents the last time we changed the file attributes, including permissions, size, attributes Wait

You can also use the stat method in C/C++ to query these three time attributes of the file. Generally, applications will use modify time to determine whether the file is updated. The reason why we are in trouble this time is because the file is operated by mv and the modity time is not updated. , so opcache is not updated.

The above has introduced the small pitfalls of opcache's detection of file updates, including cache content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!