PHP Caching

PHP caching is good way to speed up the web page. By storing relatively static data in cache and serving it from cache when requested, the application saves the time that would be required to generate the data from scratch every time.

Caching can occur at different levels and places in a Web application. On the server side, at the lower level, cache may be used to store basic data, such as a list of most recent article information fetched from database; and at the higher level, cache may be used to store fragments or whole of Web pages, such as the rendering result of the most recent articles. On the client side, HTTP caching may be used to keep most recently visited page content in the browser cache.

download (1)

APC or Alternative PHP Cache, is a free open-source opcode (operation code) caching plugin for PHP. With APC caching your PHP script executions can run more efficiently, by cutting down on dynamic PHP executions.

You can simply install and enable it.

sudo apt-get install php-apc

After that you need to enable in php.ini file as apc.enable_cli = 1

Data caching is about storing some PHP variables in cache and retrieving it later from cache. It is also the foundation for more advanced caching features, such as query caching and page caching.

Core PHP example and steps.

Yii2 Framework example:-
Yii2 framework have inbuilt classes to use caching. You can also manage cache provide like File, APC , MemCache etc.

You can found more details in the link http://www.yiiframework.com/doc-2.0/guide-caching-overview.html

HTTP Caching: You can install 2 php module and add some code to .htaccess file. This can be applied in every php project.

Note:
Query caching does not work with query results that contain resource handlers. For example, when using the BLOB column type in some DBMS, the query result will return a resource handler for the column data.
Some caching storage has size limitation. For example, memcache limits the maximum size of each entry to be 1MB. Therefore, if the size of a query result exceeds this limit, the caching will fail.

Download – Cache Master (1)

Comments