Php

How to install APC/APCu cache on WAMP and XAMPP

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,

There are two type of APC versions.

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.

How to Install PHP APC Cache on XAMPP

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.

Related Post

How To Install APCu in PHP

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.

How To Clear APC Cache

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.

How to Cache XML file in PHP

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.

There are two methods to control cache expiration:

  1. Set the expiry date time of the file from the cache folder.
  2. File dependent caching(compare file created time of cache file as well as the source file).

Sample Example:

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);
      }
  }

How To Use PHP Cache Method in HTML file

You can call the cache method as below:

checkCache();

Conclusion:

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.

View Comments

  • Way cool! Some very valid points! I appreciate you penning this
    article and the rest of the site is really good.

  • Everything is very open wiith a clear explanation of the challenges.
    It was really informative.Your website iss extremely helpful.
    Thank you for sharing!

  • Very nice reading. I've been looking for
    the same things.
    Good luck and thanks for the great read.

  • 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

Recent Posts

Configure and Retrieve S3 Information Using Laravel PHP-AWS-SDK

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

3 months ago

What is the Purpose of php_eol in PHP?

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

9 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

9 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

9 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

10 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

10 months ago

Categories