Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use opcache to optimize production Environment PHP

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use opcache to optimize the production environment PHP". In the daily operation, I believe many people have doubts about how to use opcache to optimize the production environment PHP. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to use opcache to optimize the production environment PHP". Next, please follow the editor to study!

OPcache improves the performance of PHP by storing the precompiled bytecode of PHP scripts in shared memory. The advantage of storing precompiled bytecode is that it saves the overhead of loading and parsing PHP scripts each time.

1. Php.ini configuration opchche example [opcache] zend_extension=opcache.so; switch turns on opcache.enable=1opcache.enable_cli=1; shared memory size, as appropriate, in megabytesopcache.memory_consumption=256; the memory size of interned string, and the maximum number of files cached by opcache.interned_strings_buffer=8; can also be adjusted. If the hit rate is less than 100%, you can try to increase this value opcache.max_accelerated_files=4000;60s to check for file update opcache.revalidate_freq=60. Open Quick close, open this will increase the speed of memory collection when PHP Request Shutdown opcache.fast_shutdown=1; does not save files / functions comment opcache.save_comments=0; whether to close quickly, the speed of memory recovery in PHP Request Shutdown after opening will improve opcache.fast_shutdown= 1 II, some configuration parameters description

Opcache.revalidate_freq

This configuration option is used to set the cache expiration time. If set to 0, each request will check whether the file is modified, which consumes a lot of resources, so if you do not need to use opcache for the time being, just set opcache.enable to 0.

Opcache.validate_timestamps

When configured to 1, the updated code is checked according to the value set by revalidate_freq; when set to 0, it is never checked.

When you need to update a lot of code at a time, you can set it to 0, and then set it to 1 when all the uploads are complete. Avoid system instability caused by uploading code.

Opcache.max_accelerated_files

The real value is the first prime number larger than the set value found in the prime set {223463983, 1979, 3907, 7963, 16229, 32531, 65407, 130987}.

You can run find. -type f-print | grep php | wc-l to quickly calculate the number of PHP files in your code base.

Third, it is recommended in the recommended configuration development mode. It is better to disable the opcache extension directly to opcache.revalidate_freq=0opcache.validate_timestamps=1opcache.max_accelerated_files=3000opcache.memory_consumption=192opcache.interned_strings_buffer=16opcache.fast_shutdown=1 multi-machine cluster mode or to recommend when the code is updated frequently, which can take into account the performance and facilitate the code update opcache.revalidate_freq=300opcache.validate_timestamps=1opcache.max_accelerated_files=7963opcache.memory_consumption=192opcache.interned_strings_buffer=16opcache.fast_shutdown=1 stable project recommendation. Best performance opcache.revalidate_freq=0opcache.validate_timestamps=0opcache.max_accelerated_files=7963opcache.memory_consumption=192opcache.interned_strings_buffer=16opcache.fast_shutdown=1

I hope the above can help you. Many PHPer will always encounter some problems and bottlenecks when they are advanced. There is no sense of direction when writing too much business code, and I don't know where to start to improve. I have sorted out some information about this, including but not limited to: distributed architecture, high scalability, high performance, high concurrency, server performance tuning, TP6,laravel,YII2,Redis. Swoole, Swoft, Kafka, Mysql optimization, shell script, Docker, micro-service, Nginx and other knowledge points can be shared with you for free.

At this point, the study on "how to use opcache to optimize the production environment PHP" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report