After you install APC for PHP to speed up PHP, you'll want to be able to take a look at the APC dashboard, and to clear the APC cache at times.

In this guide I'll cover how you can copy over the apc.php script included with APC to your website so you can see what the cache looks like. I'll also show you how you can either manually clear the cache, or setup a cronjob to automatically clear the APC cache on a consistent basis.

Setup APC dashboard to view cache stats

If you followed along and have already installed APC, you should still have the apc.php file on your server. Using the steps below I'll show you how to copy over this file to your website so you can view the APC cache.

  1. If you're not already, login to your server with SSH.
  2. In this example my cPanel username is userna5. Use this command to copy the apc.php file from your APC source files to your document root:

    cp -frp /usr/local/src/APC-3.1.13/apc.php ~userna5/public_html/

  3. Now you'll want to change the ownership of the apc.php script to your cPanel user with this code:

    chown userna5.userna5 ~userna5/public_html/apc.php

  4. Now visit http://example.com/apc.php to access the dashboard. apc dashboard showing cached files and hits

    You can see the number of Cached files and also how many Hits they've had, that is to say how many times APC saved your server from having to load up everything for a PHP script and instead grabbed some content from the APC cache.

Clear APC Cache

To clear the APC cache it's quite simple, just make a script called something like apc_clear.php and then add the following code to it. Make sure to replace 123.123.123.123 with your own local IP address:

<?php
if (in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1', '123.123.123.123')))
{
  apc_clear_cache();
  apc_clear_cache('user');
  apc_clear_cache('opcode');
  echo json_encode(array('success' => true));
}
else
{
  die('No valid IP');
}
?>

When you access this script directly at http://example.com/apc_clear.php from your approved IP address, or if you setup a cronjob which will connect with the server's local IP, it will clear out the APC cache for you.

This is an example cronjob setup for clearing the APC cache every 6 hours:

0 */6 * * * /usr/bin/curl --user-agent Cron http://example.com/apc_clear.php

You should now understand how to review how effective your APC cache is working for your site, and also how to clear out that cache in the event that pages aren't showing updates because they are still cached.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Like this Article?

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

News / Announcements

WordPress wp-login.php brute force attack
Updated 2014-07-17 06:43 pm EST
Hits: 200917

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!