Stop caching for PHP 5.5.3 in MAMP

前端 未结 9 1272
孤城傲影
孤城傲影 2020-11-27 10:03

Installed MAMP on a new Macbook with PHP 5.5.3.

Reload and refresh do nothing. Still nothing. Google around for a few minutes trying to find out what is wrong, come

9条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 10:39

    Took me so long to figure out it was a MAMP problem! Why would OPcache be enabled by default-- and require php.ini tinkering to disable-- in an app that's supposed to be used for testing websites? Anyway, I read through this whole thread and tried the various solutions.

    Here are my notes on how each solution works and considerations for selecting a solution.

    Each solution works on its own; no need for redundancy.


    Webpage code solution

    opcache_reset();

    
    
    • Must be added in the webpage code.
    • Forces all scripts to be reloaded.
    • Works without restarting MAMP server.

    Server configuration solutions

    Important: Use the php.ini file in /Applications/MAMP/bin/php/php5.5.3/conf/php.ini and not in /Applications/MAMP/conf/php5.5.3/php.ini. Adjust accordingly if you're using a different version of PHP.

    enable=0

    [OPcache]
    zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/opcache.so"
    opcache.memory_consumption=128
    opcache.interned_strings_buffer=8
    opcache.max_accelerated_files=4000
    opcache.revalidate_freq=60
    opcache.fast_shutdown=1
    opcache.enable_cli=1
    enable=0
    
    • Must be added under [OPcache] in php.ini.
    • Disables OPcache.
    • Requires MAMP server restart.

    opcache.revalidate_freq=0

    [OPcache]
    zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/opcache.so"
    opcache.memory_consumption=128
    opcache.interned_strings_buffer=8
    opcache.max_accelerated_files=4000
    opcache.revalidate_freq=0
    opcache.fast_shutdown=1
    opcache.enable_cli=1
    
    • Modify opcache.revalidate_freq under [OPcache] in php.ini.
    • Makes OPcache check for updates every 0 seconds instead of every 60 seconds.
    • Requires MAMP server restart.

    Commenting out [OPcache]

    ;[OPcache]
    ;zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/opcache.so"
    ;opcache.memory_consumption=128
    ;opcache.interned_strings_buffer=8
    ;opcache.max_accelerated_files=4000
    ;opcache.revalidate_freq=60
    ;opcache.fast_shutdown=1
    ;opcache.enable_cli=1
    
    • Comment out the entire [OPcache] section in php.ini.
    • Removes OPcache from the PHP server.
    • Requires MAMP server restart.

    Considerations

    Choose the webpage code solution if:

    • You just need to force script refreshing for a particular project
    • You don't want to restart the MAMP server
    • You don't want to edit php.ini

    Choose a server configuration solution if:

    • You want to disable caching by default instead of having to do it in every project
    • You're comfortable with editing php.ini

    I personally prefer enable=0 since it's the simplest solution for me, and I need caching disabled by default.


    References

    • http://php.net/manual/en/function.opcache-reset.php
    • http://php.net/manual/en/opcache.configuration.php

提交回复
热议问题