WEB HOSTING SUPPORT NETWORK
     
 

Purging the server-side cache

The server-side cache will be purged (deleted) automatically when it expires.

If you have made some changes to your content that have been cached, you can clear the server-side cache manually by using either of the following methods:

  • Control Panel's Server-side Caching section
  • cURL via the command line
  • cURL via PHP

Note: Some software applications can be configured to detect content changes and purge the server-side cache automatically for you. You can find step-by-step instructions for WordPress and Drupal in our Enabling server-side caching for WordPress and Enabling server-side caching for Drupal articles.

Control Panel's Server-side Caching section

To manually purge the server-side cache for a specific domain/subdomain, go to the Server-side Caching section of the hosting Control Panel and click on the Purge button next to the domain/subdomain name.

cURL via the command line

You can purge the server-side cache for your domain/subdomain (e.g. http://your_domain.com) manually by using the following command:

curl -X PURGE http://your_domain.com

Using the command below will delete only the server-side cache for the specified page/directory (e.g. http://your_domain.com/your_page)

curl -X PURGE http://your_domain.com/your_page

You should execute the commands listed above from your hosting account via SSH. To be able to do this, you need to make sure that Network tools are enabled for your account through the hosting Control Panel's SSH Access section. More details on how to connect via SSH to your account are available in the SSH article from our online documentation.

cURL via PHP

Add the code block listed below to a PHP file (e.g. purge_cache.php) in your website directory using the hosting Control Panel's File Manager section:

<?php
// Prevent caching for this script
header("Cache-Control: no-cache");

// Get the protocol and hostname
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$host = $_SERVER['HTTP_HOST'];

// Set the URL using the protocol and hostname
$url = $protocol . $host;

// Create a new cURL resource
$ch = curl_init();

// Set the URL
curl_setopt($ch, CURLOPT_URL, $url);

// Set the request method to PURGE
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PURGE");

// Attempt to clear the cache and print the result
echo (curl_exec($ch) ? "Successfully purged" : "Unable to purge") . " the server-side cache for " . $host . "!";

// Close cURL resource, and free up system resources
curl_close($ch);
?>

To purge the cache for your domain/subdomain, you have to simply access the file you created via a browser (e.g. http://your_domain/purge_cache.php).