The SpinupWP Cache Daemon

The cache daemon is a little Go app we’ve written and deploy to every server to help with purging the page cache. The reason we need this daemon is an issue of file permissions. Each site runs a PHP pool as the site user but since cache files are owned by user www-data PHP cannot delete the cache files. Maybe someday FastCGI Cache will have an option to have the cache files be owned by the parent folder owner, but until then we need our cache daemon.

The cache daemon listens on port 7836 for purge requests and deletes the requested path. Supervisor is used to ensure the cache daemon is always running, even after a server reboot. The daemon only listens on localhost, therefore it’s not accessible from outside the server.

Clearing the Cache

If you’re using our plugin, cache purging will be handled for you automatically when content changes. You will also have access to the following helper functions, which you can use from your own hooks:

// Purge the entire SpinupWP page cache.
spinupwp_purge_site()

// Purge a single post from the SpinupWP page cache.
spinupwp_purge_post( $post_id|$post )

// Purge a single URL from the SpinupWP page cache.
spinupwp_purge_url( $url )

The following WP-CLI commands are also available:

wp spinupwp cache purge-site
wp spinupwp cache purge-post <id>
wp spinupwp cache purge-url <url>

However, if you’re not running WordPress or do not wish to use our plugin you can manually make purge requests. A manual purge request can be made by sending a file path followed by a new line to port 7836. In PHP this might look something like this:

$path = '/cache/example.com';

$fp = @fsockopen( '127.0.0.1', '7836' );

if ( $fp ) {
    fwrite( $fp, $path . "\n" );

    $result = fread( $fp, 512 );
    fclose( $fp );

    return (bool) preg_match('/^Purge:\sSuccess/', $result);
}

The daemon will return Purge: Success\n or Purge: Error\n depending on whether the path could be deleted. If the path doesn’t exist, success will be reported. For security reasons, only paths within the /cache/ directory can be deleted.

Start Your 7-Day Free Trial

Start your SpinupWP journey today and spin up your first server within minutes.

Start Your Free Trial

No credit card required

Subscribe to get the latest news, updates and optimizations in performance and security.

Thanks for subscribing 👍

To receive awesome stuff, you'll need to head to your inbox and click on the verification link we sent you.
Make sure to check your "spam" folder or your "promotions" tab (if you have Gmail).
If you're still having trouble, then messages us at sudo@spinupwp.com.

You are already logged in

It looks like you are already logged in to SpinupWP.

Please log out of this account to continue.

Registration Successful

Thanks for registering for a new
SpinupWP account.

Before getting started, could you verify your email address by clicking on the link we just emailed to you?

SpinupWP

Free Trial

Start Your 7-Day Free Trial

No credit card required. All features included.

By signing up to SpinupWP, you agree to our Terms and Conditions.
For privacy related information, view our Privacy Policy.