How To Enable PHP 5.5 Opcache
Install Requirements
yum install gcc httpd-devel php-pear pcre-devel
Install Zend Opcache
yum install php-pecl-zendopcache
This will install Zend Opcache.
PHP 5.6.9 (cli) (built: May 28 2015 00:59:21)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
On nginx (php-fpm)
[root@ip-172-31-29-134 ec2-user]# php-fpm -v
PHP 5.6.9 (fpm-fcgi) (built: May 28 2015 01:00:40)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
;opcache.memory_consumption=64
to
opcache.memory_consumption=128
;opcache.max_accelerated_files=2000
to
opcache.max_accelerated_files=4000
;opcache_revalidate_freq = 2
to
opcache_revalidate_freq = 240
yum install gcc httpd-devel php-pear pcre-devel
Install Zend Opcache
yum install php-pecl-zendopcache
This will install Zend Opcache.
Restart Server
You will need to restart your server after installation for this to take effect:
sudo service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
Test Installation
[root@ip-172-31-29-134 ec2-user]# php -vPHP 5.6.9 (cli) (built: May 28 2015 00:59:21)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
On nginx (php-fpm)
[root@ip-172-31-29-134 ec2-user]# php-fpm -v
PHP 5.6.9 (fpm-fcgi) (built: May 28 2015 01:00:40)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
Modify the Amount of RAM the Opcache Will Use
With Opcache, there is a trade-off between speed and the amount of RAM used. The more RAM you are willing to dedicate to storing opcode, the more opcode that can be stored. There is a diminishing return at some point because some code will execute rarely, or your code base might not be that big. It is worth playing with this setting to see where you get the best performance vs. RAM trade-off. This setting is in megabytes.;opcache.memory_consumption=64
to
opcache.memory_consumption=128
Boost the Number of Scripts that Can Be Cached
Opcache has a strange setting that requires you to not only adjust the amount of RAM, but also define the number of scripts that can be cached. You have the option of tuning this parameter for your own application too, especially if you find that your hit rate is not close to 100%.;opcache.max_accelerated_files=2000
to
opcache.max_accelerated_files=4000
Change the Revalidate Frequency
To make sure that the Opcache notices when you change your PHP code, you can set the revalidate frequency. Basically, this will tell the cache how often to check the timestamp on the files. This is measured in seconds.;opcache_revalidate_freq = 2
to
opcache_revalidate_freq = 240
Web Viewer (monitor tool)
1) Opcache-Status by Rasmus Lerdorf
Installwget https://raw.github.com/rlerdorf/opcache-status/master/opcache.php
2) opcache-gui by amnuts
Installwget https://raw.github.com/amnuts/opcache-gui/master/index.php -O op.php
Nhận xét
Đăng nhận xét