Opcache detection Files Update the PIT. BD SAPI Cache Cache The Chinese translation is the cache cache how to read

Source: Internet
Author: User
Tags sapi
Data-id= "1190000004975909" data-licence= "" >

Last night, the line went out of trouble, emergency deal with the disaster after the handover to alleviate the failure, after resolving the disaster after calmly switch back to the official service, found that the PHP file update invalid, restart FPM after the effective. The following records the process of tracing the disc.

Because it is PHP file update does not take effect, so immediately suspected opcache above, to the line looked at php.ini, sure enough used opcache, and the detection interval is set to 60 seconds. View last night's log, the update does not take effect longer than 60 seconds, so this detection interval time problem can pass, we continue.

On-line environment to view the updated files and the time in the log, suddenly found that the PHP file time and the time in the log does not correspond, immediately find the OP Confirmation, Op confessed that this file is back to roll the MV back, so the file time and I expected inconsistent. I looked at it with a stat command, and sure enough. Modify time is a bit earlier than access, and based on this clue, Opcache relies on the PHP file's modify as the detection condition for the file being modified. Online to reproduce the problem, pits success!

The following summarizes some of the relevant knowledge points in the process of pits

Load Opcache

When adding Opcache to php.ini, you need to use zend_extension instead of extension, or 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

Configure Opcache

Use the following recommended settings to achieve better performance:

opcache.memory_copcache.interned_strings_buffer=8opcache.max_accelerated_files=4000opcache.revalidate_freq=60opcache.fast_shutdown=1opcache.enable_cli=1

There are two parameters involved in this session

Revalidate_freq, default 2
Checks whether the script timestamp has an updated period, in seconds. Setting to 0 causes Opcache to check for script updates for each request

Validate_timestamps, default 1
If enabled, the Opcache will check if the script is updated every opcache.revalidate_freq set number of seconds. If you disable this option, you must manually reset the Opcache using the Opcache_reset () or opcache_invalidate () function, or you can make the file system changes take effect by restarting the WEB server.

system commands and Functions stat

Access time indicates when we last accessed the file
Modify time indicates when we last modified the file
Change time indicates the last times we changed the properties of a file, including permissions, size, attributes, and so on.

The modify can also use the Stat method to query the file's 3 time properties, the general application will determine whether the file is updated by the time of day, we step on the pit is because the file is MV operation, modity Times is not updated, so opcache not updated.

The above describes the Opcache detection file update of the pit, including the content of the cache, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.