Skip to content

Commit 183ce6c

Browse files
committed
Feature: Reset PHP OPcache
1 parent 89ff232 commit 183ce6c

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

recipe/common.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
require __DIR__ . '/deploy/lock.php';
1313
require __DIR__ . '/deploy/push.php';
1414
require __DIR__ . '/deploy/release.php';
15+
require __DIR__ . '/deploy/reset_opcache.php';
1516
require __DIR__ . '/deploy/rollback.php';
1617
require __DIR__ . '/deploy/setup.php';
1718
require __DIR__ . '/deploy/shared.php';

recipe/deploy/reset_opcache.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Deployer;
4+
5+
set('reset_opcache_nonce', bin2hex(random_bytes(8)));
6+
set('reset_opcache_document_root', '{{release_or_current_path}}');
7+
set('reset_opcache_app_url', 'https://{{hostname}}');
8+
9+
desc('Place PHP OPcache Reset Script');
10+
task('deploy:reset_opcache:prepare', function () {
11+
$phpScript = <<<PHP
12+
<?php
13+
if (function_exists("clearstatcache")) {
14+
clearstatcache(true); // Clear realpath cache
15+
}
16+
if (function_exists("opcache_reset")) {
17+
opcache_reset(); // Clear opcache
18+
}
19+
@unlink(__FILE__);
20+
echo "success";
21+
PHP;
22+
23+
run('echo "$PHP_OPCACHE_RESET_SCRIPT" > {{reset_opcache_document_root}}/reset_opcache-{{reset_opcache_nonce}}.php', env: ['PHP_OPCACHE_RESET_SCRIPT' => $phpScript]);
24+
});
25+
26+
desc('Execute PHP OPcache Reset');
27+
task('deploy:reset_opcache:execute', function () {
28+
$result = fetch("{{reset_opcache_app_url}}/reset_opcache-{{reset_opcache_nonce}}.php");
29+
if ($result !== 'success') {
30+
throw error('Reset PHP OPcache failed!');
31+
}
32+
});
33+
34+
desc('Reset PHP OPcache');
35+
task('deploy:reset_opcache', [
36+
'deploy:reset_opcache:prepare',
37+
'deploy:reset_opcache:execute',
38+
]);

0 commit comments

Comments
 (0)