In this tutorial, I will demonstrate How to install the PHP APC and APCu cache module on your PHP environment (WAMP/XAMPP). First, we will ensure about our version of the APC cache which is based on the compiler version. We will learn how to install PHP APC and APCu Cache on WAMP and XAMPP server in windows.
The APC is not compatible with PHP 5.5+ version, So I have added steps to configure APCu which is supported by PHP 5.5+.
APC is a great op-code caching system for PHP that can help speed up your website. APC Cache helps to bypass the parsing and compiling steps and minimizes web requests to the server.
Also checkout other tutorial of PHP Cache,
1- VC6
2- VC9
If your PHP compiler version is “Compiler: MSVC6 (Visual C++ 6.0)”, Then we need to APC VC6 version Otherwise APC VC9 version. We will check the compiler version from phpinfo file of the wamp server.
Step 1: We will download require a version of php_apc.dll
file from here
As per my compiler, I downloaded ‘APC 3.1.6 for PHP 5.3 vc6’.
Step 2: Let’s copy the above dll file and paste it into c: /wamp/bin/php/ext/
folder.
Step 3: We will restart the wamp or machine.
Step 4: Enabled APC module from PHP Extension list.
Step 5: Paste the below configuration parameter into C:\wamp\bin\apache\Apache2.2.17\bin\php.ini
file
[APC] apc.enabled = 1 apc.shm_segments = 1 apc.shm_size = 64M apc.max_file_size = 10M apc.stat = 1
Step 6: Restart the wamp server or Machine.
Step 7: Open the PHP info file of the wamp server.http://localhost/?phpinfo=1
If we will find the APC module configuration in PHP info file then everything is OK and installed otherwise something is wrong.
You can follow the below steps to install the PHP APC cache on XAMPP server. XAMPP is also commonly used by the developer for PHP development, So I am here to share steps to install APC php cache into xampp.
Step 1: Put the .dll
(which you have downloaded from the above step) file into php/ext
folder.
Step 2: Open php.ini
configuration file and find 'extension : php_apc.dll'
, if you did not found then add this line otherwise remove the semi-colon before the extension.
Step 3: Restart the Xampp server check the phpinfo()
and search APC if it’s found that means APC is Successfully installed on your server.
I have configured APC on xampp/wampp, but APC is not supported by PHP 5.5+ version. We will install APCu and configure which is compatible with PHP 5.5+. You can install APCu for wamp and xampp.
There are the following steps to follow to configure APCu.
Step 1: We will download require a version of APCu file from here.
This page will have a table with all available releases.
Step 2: Let’s copy the above dll file and paste it into c:/wamp/bin/php/ext/
folder.
Step 3: We will restart the wamp or machine.
Step 4: Enabled APC module from PHP Extension list.
Step 5: Paste the below configuration parameter into C:\wamp\bin\apache\Apache2.2.17\bin\php.ini
file
[apcu] extension="C:\wamp\bin\php\php5.5.12\ext\php_apcu.dll" apc.enabled=1 apc.shm_size=32M apc.ttl=7200 apc.enable_cli=1 apc.serializer=php
Step 6: Restart the wamp server or Machine.
Step 7: Open php info file of the wamp server.http://localhost/?phpinfo=1
Let’s check if apcu configuration table appears and apcu module is enabled, then everything is OK and installed otherwise something is wrong.
We can clear the APC cache using PHP script. Let’s create apc_clear.php
file and add the below code into this file. Please make sure to replace xxx.xxx.xxx.xxx
with your own machine IP address:
if (in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1', 'xxx.xxx.xxx.xxx'))) { apc_clear_cache(); apc_clear_cache('user'); apc_clear_cache('opcode'); echo json_encode(array('success' => true)); } else {die('No valid IP');}
You can run your script directly at https://yourwebsite.com/apc_clear.php
l clear out the APC cache for you.
Let’s take a simple example to cache a file. Normally, we are accessing web services and the method is accessing data very frequently. The web method response does not change frequently.
At that point, if we are accessing each time web service, it’s very costly in terms of website performance.
At that time we will keep an XML copy of the response in the cache folder and use it again and again until the response will not change.
Now our mind has a question on how to identify the response or file has been changed.
Below is the code to create a cache file with fixed expiry DateTime.
function checkCache() { $path = 'cache/phpflow.xml'; $oriFile = ' phpflow.xml'; if ((!file_exists($path) || time() - filemtime($path) > 60) && $cache = fopen($path, 'w+')) { fwrite($cache, file_get_contents($oriFile)); fclose($cache); } else { $cache = fopen($path, 'r'); return file_get_contents($path); fclose($cache); } }
You can call the cache method as below:
checkCache();
In this PHP APC cache tutorial, We have learned about the installation of PHP APC/APCu cache on WAMP and XAMPP server. I hope it helps you and feel free to post your suggestions and questions in the comment section.
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More
View Comments
Thanks Michael
Way cool! Some very valid points! I appreciate you penning this
article and the rest of the site is really good.
ңi there! I simply want to offer you a huge thumbѕ up for your great info you
have here on this post.
Everything is very open wiith a clear explanation of the challenges.
It was really informative.Your website iss extremely helpful.
Thank you for sharing!
Good blog post. I definitely love this site. Continue the good work!
Very nice reading. I've been looking for
the same things.
Good luck and thanks for the great read.
Great post.
The last PHP version that had the php_apc extension included in was PHP 5.3. * Newer versions of PHP have replaced APC with php_opcache.even enabling zend on wamp will solve purpose