Clear APC cache in PHP

Tired of the privacy invasion of browsers? Worried about the risk of seeing ads everywhere? Give the Brave Browser a try. All Chrome extensions are compatible. None of the telemetry. Auto-blocks ads and still support content creators like me.

Download the Brave browser now »

Profile image of Mattias Geniar

Mattias Geniar, November 16, 2014

Follow me on Twitter as @mattiasgeniar

How do you clear the APC cache? There are basically two methods: as a PHP developer, you can use the built-in PHP functions – or as a SysAdmin, you can restart the necessary services to flush the APC cache.

As a PHP developer

You can call the apc_clear_cache() function to clear the cache. To clear the user cache (key/value), you can use apc_cache_clear('user'). To clear the system cache, the one that holds the byte-code of the PHP files (the so called “opcode” cache), just call apc_cache_clear() without options.

As a System Administrator

This depends on the way you run your PHP application.

With Apache + mod_php

As PHP is run as an Apache module, it’s sufficient to reload the Apache service. A restart is not needed (but it will also work), a reload is sufficient.

$ service httpd reload
$ service apache2 reload


This can be used with Nginx, Lighttpd or even Apache. If your PHP server is running as a daemon via PHP-FPM, you can reload PHP-FPM.

$ service php-fpm reload

If this is how you’re running your PHP stack, you may consider using multiple PHP-FPM masters as outlined in “A better way to run PHP-FPM”, as it gives you an APC cache per PHP-FPM pool you are running.

As the built-in PHP server

If you start your PHP daemon via the built-in server, as php -S, you need to restart your daemon. That probably means sending a kill signal to the PHP process and starting it anew.

PHP as FastCGI

Not to be confused with running PHP as the PHP-FPM daemon, in the older days PHP was run as a FastCGI script. There’s no need to clear the APC cache, as it gets invalidated on every new request – each request starts a new process. In fact, you’re better of disabling APC altogether, as it produces overhead that never gives you the benefits.

Want to flush the Opcache instead of APC? Check out this article: How to clear PHP’s Opcache.

Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.