OPcache Clear - Deployment Pipeline
Foreword
The PHP process of the web server differs from the PHP process of the CLI environment. In view of this, it is not possible to clear the PHP OPcache via CLI.
Clear Script Deployment
The following PHP script must be provided in the document root directory of the Shopware 6 application:
Example path:
/var/www/creoline-demo.com/releases/current/public/opcache.php opcache.php
<?php
$allowList = [
'127.0.0.1',
'10.20.0.1',
'10.20.0.2',
'10.20.0.3',
'10.20.0.4',
];
header('Content-Type: text/plain');
if(!in_array($_SERVER['REMOTE_ADDR'], $allowList)) {
http_response_code(403);
echo "The ip {$_SERVER['REMOTE_ADDR']} is not allowed to execute this script.\n";
return;
}
$status = opcache_get_status(false);
if(!$status['opcache_enabled']) {
http_response_code(400);
echo "OPcache is not enabled.\n";
return;
}
$memoryUsed = round($status['memory_usage']['used_memory'] / 1024 / 1024);
$memoryFree = round($status['memory_usage']['free_memory'] / 1024 / 1024);
if(opcache_reset()) {
http_response_code(200);
echo "OpCache has been cleared successfully. Used memory: {$memoryUsed} MiB - Free memory: {$memoryFree} MiB\n";
} else {
http_response_code(400);
echo "OpCache could not be cleared.\n";
} The IP addresses in AllowList must be adapted to the VPC IP addresses of the app servers.
Deployment Integration
In the last step, after the symlink flip, the script must be called by each app server as follows:
curl -k --fail-with-body --retry 3 --retry-all-errors http://127.0.0.1/opcache.php -H "Host: www.creoline-demo.com" The Host header must be adapted to the corresponding domain specified in the NGINX Vhost Config. If no domain has been specified, the host header can be omitted.
Error handling
Success
- cURL Exitcode:
0 - The OPcache was successfully cleared
Error
- cURL Exitcode:
22 - The OPcache could not be emptied even after 3 attempts. Error analysis see HTTP-Body.
Similar articles
Was this page helpful?