function varnish_purge_paths in Varnish 7
Same name and namespace in other branches
- 8 varnish.module \varnish_purge_paths()
Helper function that wraps around varnish_purge().
Compiles a regular expression of all paths supplied to it. This function takes care to chunk commands into no more than 7500 bytes each, to avoid hitting params.cli_buffer.
Parameters
string $host: The host to purge.
array $paths: The paths (no leading slash) to purge for this host.
1 call to varnish_purge_paths()
- varnish_expire_cache in ./
varnish.module - Implements hook_expire_cache().
File
- ./
varnish.module, line 219 - Common functions used for the module.
Code
function varnish_purge_paths($host, array $paths) {
// Subtract the hostname length from the global length limit.
// Note we use strlen() because we're counting bytes, not characters.
$length_limit = variable_get('varnish_cmdlength_limit', 7500) - strlen($host);
$base_path = base_path();
while (!empty($paths)) {
// Construct patterns and send them to the server when they're full.
$purge_pattern = '^';
while (strlen($purge_pattern) < $length_limit && !empty($paths)) {
$purge_pattern .= $base_path . array_shift($paths) . '$|^';
}
// Chop the final "|^" off the string, leaving "$".
$purge_pattern = substr($purge_pattern, 0, -2);
// Remove extra slashes in beginning of URL.
$purge_pattern = preg_replace('#/+#', '/', $purge_pattern);
// Submit this purge chunk.
varnish_purge($host, $purge_pattern);
}
}