Recommended (free): PHP7
##No matter where I am, I will reply you immediately when I see the email.My Email: echo "YUBzYW1lZ28uY29tCg==" | base64 -d
PrefaceIt's half past eleven, and it's time to settle.
When PHP is running, there is such a process. The PHP code is first pre-compiled, the bytecode is generated and then loaded into the memory. Finally, the CPU executes the compiled bytes on the memory. code fragment. We will find that when executing a PHP program, we go through such a process every time. This is not a waste of time. Yes, it is easy to think: Why not follow the C language and compile the source code into a file that can be directly loaded into the memory so Where is brother? Uh-huh?. Get out your rifle and load this bulletOPcache
. Since PHP5.5.0 came out, this zend extension has been built-in.
What is OPcache
OPcache is a Zend extension in PHP that can greatly improve the performance of PHP.
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.
Judge whether it has been extended OPcache
➜ ~ php -m | grep OPcache Zend OPcache Zend OPcache
If it is not enabled, you can enable it in the php.ini configuration/home /samego/service/php7.2/php.ini
➜ ~ echo zend_extension="opcache.so" >> /home/samego/service/php7.2/php.iniCopy after login
About OPcache configureNext, we need to enable OPcache in the PHP configuration file (The default is closed):
opcache.enable=1
opcache.memory_consumption=512
opcache.interned_strings_buffer=64
opcache.max_accelerated_files=32531
opcache.validate_timestamps=0
opcache.save_comments=1
opcache.fast_shutdown=0
opcache.enable=1 opcache.memory_consumption=512 opcache.interned_strings_buffer=64 opcache.max_accelerated_files=32531 opcache.validate_timestamps=0 opcache.save_comments=1 opcache.fast_shutdown=0
You can experiment with these configuration values. The specific configuration values depend on your application size and server configuration. Learning from the Laravel Community
Laravel OPcache
➜ ~ composer require appstract/laravel-opcache
➜ ~ php artisan vendor:publish --provider="Appstract\Opcache\OpcacheServiceProvider" --tag="config"
# Clear OPcache: ➜ ~ php artisan opcache:clear # Show OPcache config: ➜ ~ php artisan opcache:config # Show OPcache status: ➜ ~ php artisan opcache:status # Pre-compile your application code: ➜ ~ php artisan opcache:optimize
Scenario test to wait and see
Personally, I prefer the data-speakingscenario: (1) Requesting the GET interface (2) The number of tests is 10 (3) The number of concurrency is 100
case non-extension
1000 requests, took 32.32 seconds, 30.94 requests per secondTransactions: 1000 hits Availability: 100.00 % Elapsed time: 32.32 secs Data transferred: 0.97 MB Response time: 0.32 secs Transaction rate: 30.94 trans/sec Throughput: 0.03 MB/sec Concurrency: 9.96 Successful transactions: 1000 Failed transactions: 0 Longest transaction: 0.44 Shortest transaction: 0.11Copy after login
case had extend
1000 The request took 2.94 seconds, 340.14 requests per secondTransactions: 1000 hits Availability: 100.00 % Elapsed time: 2.94 secs Data transferred: 0.97 MB Response time: 0.03 secs Transaction rate: 340.14 trans/sec Throughput: 0.33 MB/sec Concurrency: 9.86 Successful transactions: 1000 Failed transactions: 0 Longest transaction: 0.29 Shortest transaction: 0.01Copy after login
I was very happy to see this set of data, extremely happy. In terms of performance, there is such a sharp contrast that I won’t say anything ~OPcache is right
The above is the detailed content of Tips to improve PHP7 performance using OPcache extension. For more information, please follow other related articles on the PHP Chinese website!