Opcache: Difference between revisions

235 bytes added ,  19 March 2018
added links
(initial documentation of Opcache tuning)
 
(added links)
 
Line 3: Line 3:
Meza installs <code>php56u-opcache</code> in <code>/opt/meza/src/roles/apache-php/tasks/php.yml</code> and sets <code>opcache.interned_strings_buffer=4</code> in /opt/meza/src/roles/apache-php/templates/php.ini.j2</code>
Meza installs <code>php56u-opcache</code> in <code>/opt/meza/src/roles/apache-php/tasks/php.yml</code> and sets <code>opcache.interned_strings_buffer=4</code> in /opt/meza/src/roles/apache-php/templates/php.ini.j2</code>


In raising the setting we also optimized the PHP opcache according to the '''Scaling PHP''' book recommendations.
In raising the setting we also optimized the PHP opcache according to the '''[https://www.scalingphpbook.com/blog/2014/02/14/best-zend-opcache-settings.html Scaling PHP]''' book recommendations.


Also, in order to effectively monitor our actual usage of the Opcache, I installed Rasmus Ledorf's (creator of PHP): https://github.com/rlerdorf/opcache-status.git for instances where the deploy mode is 'development'. Note: There are a few (simple+good) pull requests that have sat idle for a long time, so it might be better to use a fork, or create a fork instead of using Rasmus' repo.
Also, in order to effectively monitor our actual usage of the Opcache, I installed Rasmus Ledorf's (creator of PHP): [https://github.com/rlerdorf/opcache-status.git opcache-status] for instances where the deploy mode is 'development'. Note: There are a few (simple+good) pull requests that have sat idle for a long time, so it might be better to use a fork, or create a fork instead of using Rasmus' repo.


Opcache status does reveal document root and physical script path information so it's best to keep it 'private' (hence why we only install it in development). I've left out details on installation e.g. and Apache configuration to restrict access to opcache.php.  
Opcache status does reveal document root and physical script path information so it's best to keep it 'private' (hence why we only install it in development). I've left out details on installation ([https://github.com/rlerdorf/opcache-status/pull/50/files see example]). Apache configuration to restrict access to opcache.php.  


<code>Opcache.max_accelerated_files</code> should be larger than the number of files in your project. We have ~7455, <ref>
<code>Opcache.max_accelerated_files</code> should be larger than the number of files in your project. We have ~7455, <ref>
Line 17: Line 17:
</ref> and the next prime number is 7963. So let's set it to 7963 (currently 20,000)
</ref> and the next prime number is 7963. So let's set it to 7963 (currently 20,000)


One big change recommended by the book is to never re-validate file timestamps in production...it's wasting valuable time with stat calls. Instead, the book says re-validate in the dev environment, and whenever you push to production, restart your webserver.
One big change recommended by the book is to never re-validate file timestamps in production...it's wasting valuable time with stat calls. Instead, the book says re-validate in the dev environment, and whenever you push to production, [https://www.cyberciti.biz/faq/unix-linux-restart-php-service-command/ restart your webserver].
<blockquote>
<blockquote>
"Yes, this is a pain in the ass, but you should use it. Why? While you're updating or deploying code, new code files can get mixed with old ones— the results are unknown. It's unsafe as hell."
"Yes, this is a pain in the ass, but you should use it. Why? While you're updating or deploying code, new code files can get mixed with old ones— the results are unknown. It's unsafe as hell."