View and clear PHP APC cache Updated on August 16, 2021 by InMotion Hosting Contributor 2 Minutes, 19 Seconds to Read Of note, APC has been discontinued. Instead, check out the NGINX Cache Manager for your PHP caching needs. 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. If you’re not already, login to your server with SSH.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/ 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 Now visit https://example.com/apc.php to access the dashboard. 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 https://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 https://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. Share this Article InMotion Hosting Contributor Content Writer InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals! More Articles by InMotion Hosting Related Articles How to Fix the “550 No Such User Here” Email Error What is Node.js? How to Deploy Websites Generated by AI Builders on Your Server How to Use robots.txt Disallow to Block Crawlers and Protect Site Performance Content Security Policy (CSP) Headers – Complete Reference Guide Troubleshooting SSL Connection Errors: How to Fix HTTPS Issues How to Check and Repair a Database in phpMyAdmin 21 Reasons Your Website is Slow and How to Speed it Up Website Transfer Resources Ensure a Successful Website Transfer
I recommend you consider this StackOverflow answer, another another optimization option, or contacting Google directly.
I’m using file: $VERSION=’$Id: apc.php 325483 2012-05-01 00:34:04Z rasmus $’; If you open the apc.php file in a text editor: look in the top of the document for the section just below ‘BEGIN OF DEFAULT CONFIG AREA’. Look for the snippet declaring default values for ADMIN_USERNAME & ADMIN_PASSWORD. When you change these variables, you set the password on the apc.php file. Save the file, upload it and navigate to the page with a browser. Click the ‘Login’ button on the upper right of the page and enter the credentials you just changed. When you successfully log in, a button will appear below the login button location in the upper right that says ‘clear opcode cache’ Click the button and the cache will clear.