Book Image

Building a Web Application with PHP and MariaDB: A Reference Guide

By : Sai S Sriparasa
Book Image

Building a Web Application with PHP and MariaDB: A Reference Guide

By: Sai S Sriparasa

Overview of this book

Table of Contents (17 chapters)
Building a Web Application with PHP and MariaDB: A Reference Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Advanced caching techniques


In the last two sections, we discussed database caching and memory caching to store data for faster retrieval. In this section, we will go over caches such as OpCache and Varnish. PHP is an interpreter language and the code has to be executed every single time. The process of execution happens in two steps, where the code is converted into operational byte code and is then executed. PHP 5.5 arrives with OpCache that caches the precompiled bytecode present in the memory and executes it. Though OpCache arrives by default with PHP 5.5, it is not enabled by default. To enable OpCache, we have to modify our php.ini file, as shown in the following code from /etc/php5/apache2/php.ini:

opcache.enable=1
opcache.memory_consumption=64
opcache.use_cwd=1

In this snippet, we enable OpCache and allocate 64 MB of memory for storing the bytecode. We also enable the use_cwd setting to append the current working directory to the script key. This will avoid any collisions between our...