A faster website with Caché and Caché of Objects
Do you have a dynamic website built with MySQL and PHP? If your website and your audience grow, there may be a problem with website performance. Without any cache mechanism, your website is slow if your website gets more visitors than the web server can manage. Do you like to know more about the php cache, Redis and Memcachad? Continue reading …
Why do your website need a PHP cache?
A dynamic website without cache cannot manage many visitors. If a visitor accesses a dynamic website, all database consultations and Script PHP executions will use RAM and CPU power. As all server resources are limited, your website and your website will become slow or not available.
For example …
We tried a page of a WordPress website creation. We did the first test without activating the cache. During the test, the need for the CPU to work harder and the load was a bit high. At the moment when 50 concurrent users visited the website, 15 PHP processes have been used. The URL’s load time (95th percentile) was more than 100 ms.

Then we did the same test with the cache activated. The load was much lower and the CPU was not used at all. Currently only 5 PHP processes have been used that 50 concurrent users have visited the site. The cache version was much faster with less than 50 ms, the URL load time (95th percentile).

The difference is not so large, except for the PHP process number (15 vs 5).
What kind of pHP cache can you use to speed up your website?
There are different types of cache type and they all have different functions. Our list includes only the type of server side cache used along with the PHP scripts. Other types of cache, such as browser cache, database cache or proxy cache are not the reach of this article.
Full page caching
The page cache is the most important PHP cache type. As the name implies, the whole PHP page will be in a cache. In most cases, the cache version is stored for a specific time on the server’s hard disk.
If you are searching for “PHP CACE”, you will find on the PHP CAU web site. The PHP Cache company is the host of different Caché PHP libraries and APC adapters, Redis, Memcachad, Filesystem and many others. Their PHP libraries are not well taken care of over the last time, and their tips are to use the Symfony Cau Cau component for new projects.
Sinds most of the professional libraries are parts of the largest PHP frames, it is not so easy to find a good library in Caché PHP. But I found a …
Paycache
This Caché library is perhaps the best option for initial PHP developer. It is easy to install and you can adapt the required code to existing PHP scripts. Although your PHP -based website is older and written with procedural code, Pagecache is a good option. The following is a brief summary of the most important features.
- It works outside the box with zero settings.
- COMMAD CAU compatible with PSR-16 (Redis or Memcachad).
- Page caching integrated for mobile devices.
Example Pagecache PHP
As I said, using Pagecache is simple. Just install the library by composer and add the following PHP code fragment to the top of the PhP script and the Caché PHP Caché Library will create and provide the Caché file.
PAGE CHAP PHP and Popular Marks
If you start a new project, you must always consider a PHP frame like Laravel, Symfony, Codeinditer, Yii or Zend. They offer all their own complement or component of the PHP cache. If you use a PHP frame, you don’t have to write the entire code and because the most important libraries are already grouped. You don’t need to choose (and try) all the necessary libraries for yourself.
Most of the PHP cache components are capable of making the whole PHP pages cache and also provide adapters for a cache of objects with redis or memcachad.
Caché of objects
While the cache falls an entire page occurs in the file system, the cache of the object works differently. Object cache is mainly used to store chains, snatch objects or even sets of database results. These objects are stored in the RAM and sometimes in a database. For this post on the blog I will tell you more about two storage systems that you can use as an objects cache: Memcachad and Redis.
What is Memcached?
Memcachad was originally developed in 2003 by Brad Fitzpatrick. This is quite old, in the same year we have been using PHP 4 and MySQL 3.2.3. You can use Memcached with different programming languages and for PHP there are 2 extensions, one is called the object cache and the other is called a memcache (notice the “D”). Do not use the last one, it is not very well kept.
Memcachad is very fast and can help you speed up your website by keeping your load on your database at low level (ER).
Example of Memcachad PHP
Adding and reading objects is very easy and requires less code than adding / obtaining the same information from a MySQL database.
Falls from reddish objects
Redis is a data structure warehouse in memory, mainly maintained by Salvatore Sanfilippo and sponsored by Redis Labs. You can install the PHPredis extension using PECL. Currently you cannot find any information on this extension through the PHP documentation. It really is not a problem, because Redis is very popular in the world of development and there is a lot of information available online.
Example PHP Redis
The functions or methods are very similar to the code we have used for Memcachad.
What a cache of objects you choose depends on you, both are fast and easy to use. Personally, I like structured PHP documentation for Memcachad.
Understand why PHP libraries and frames use Redis or Memcachad adapters. You can use the same methods for storing your data in different objects cache systems.
Fragment caching
This cache looks a bit like pages cache, but is used to create a cache version for parts of a web page. This is very useful if some part of the page should be dynamic. A very simple example is the text “Hello user” on a website of the portal, where all the information is the same for all users, except the name.
You can store code fragments such as page cache through the file system or you can get an objects cache.
This PHP cache works differently. The html code generated as a page cache, but the php code of the script, is not the cache. PHP OPCACHE compiles the PHP code and will store this version within the RAM. In this way, PHP is able to process the PHP code much faster while using less CPU power. Some important functions of PHP OPCACHE are:
This library of Caché PHP is one of the largest projects and is not part of a framework. If you need a cache for a high -traffic website, Phpfastcache is the library you need. You can use the library for different types of cache such as a file cache, SQLite, Mongodb, Redis and Memcachad.
Example of Phpfastcache
With the following code, we get the same object as for the example of a memachad code. It is a bit more code, but if you change some of the values, you can use the same code for redis or other cache system.
Php cache and wordpress
Like this WordPress website (or blog), I do a lot of web development work with WordPress these days. There are a couple of mature cache plugins to create a full -page cache and also some plugins for the cache of objects with Redis or Memcachad. WordPress has its own objects cache interface. This will say if you connect the API of the cache of objects with memcachad and store some value within an object, the value is not stored in the database, but to Memcachad.
This is followed by a list of WordPress cache plugins I use frequently.
Wp super cache
If your server is based on Apache, this page cache supplement is very fast and stable. It is maintained by Automatic, the company behind WordPress. It does not offer objects cache, but it supports fragment cache (for advanced user).
Wp rocket
This complement to WordPress cache is also a full -page cache supplement, but it has good extras (Cloudflare integration, user cache …) and a very nice interface. This complement is not free, but in my opinion every penny is worth it. I use WP Rocket for various websites and the supplement saved me 1 second of load time (compared to WP Super Cache).
Simple cache
This simple cache complement developed by Taylor Lovett is not so popular, but it has an almost unique feature: the cache of objects (Memcachad or Redis). It does not have many options, it only enables the cache and you have finished.
I found a simple cache while looking for a complement that reproduces well with NGINX. With a simple cache, just change a row in the NGinx settings. You can also use the other two plugins for NGinx, but you have to change (and try) more NGINX settings. Ask -Me if you want to know what I changed to NGINX by WP Rocket.
Conclusion
What kind of PHP cache is the best, depends on your web application, the server settings and the possible load of the server. PHP cache is often not a simple task. If you want to do something simple, just use WordPress and one of the cache plugins available.
Posted in: PHP Scripts · Website Development
Technology
Berita Olahraga
Lowongan Kerja
Berita Terkini
Berita Terbaru
Berita Teknologi
Seputar Teknologi
Berita Politik
Resep Masakan
Pendidikan
Related Post
- June 30, 2023
- by anak
- 0
- 2:47 pm
Latto presents Cardi B a $10K Chanel bag: ‘Friendship targets’
This star has received the friendship “Lottery.” Cardi B shared a lavish present from her…- July 21, 2023
- by anak
- 0
- 2:34 pm