Skip to content

Commit c249550

Browse files
committed
Add Super Page Cache purger script and copy /etc/demyx directory with proper ownership
1 parent d815bf5 commit c249550

3 files changed

Lines changed: 89 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# CHANGELOG
2-
Entries before tag-* affects all tags.
2+
Entries before tag-* affects all tags.
3+
## 2026-05-14
4+
- Added a cache purger script for the Super Page Cache plugin
35
## 2026-05-11
46
- Update `tag-latest/Dockerfile` to force `error_log = /proc/self/fd/2` in both `/etc/php83/php-fpm.conf` and `/etc/php84/php-fpm.conf`
57
- Update `tag-latest/bin/demyx-sudo` PHP switcher to create `/var/log/php83/error.log` and set ownership to `demyx:demyx` so non-root PHP-FPM startup does not fail on default Alpine log path

tag-latest/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ RUN set -ex; \
158158

159159
# Imports
160160
COPY bin /usr/local/bin
161+
COPY --chown=demyx:demyx etc /etc/demyx
161162

162163
# Finalize
163164
RUN set -ex; \
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
if (PHP_SAPI !== 'cli') {
6+
fwrite(STDERR, "Error: wp-cloudflare-page-cache-purge.php can only be run from CLI.\n");
7+
exit(1);
8+
}
9+
10+
$demyxPath = getenv('DEMYX');
11+
12+
if (!is_string($demyxPath) || trim($demyxPath) === '') {
13+
fwrite(STDERR, "Error: DEMYX environment variable is not set. It must point to your WordPress root path.\n");
14+
exit(2);
15+
}
16+
17+
$demyxPath = rtrim(trim($demyxPath), '/');
18+
$wpLoadPath = $demyxPath . '/wp-load.php';
19+
$wpConfigPath = $demyxPath . '/wp-config.php';
20+
21+
if (!is_file($wpLoadPath)) {
22+
fwrite(STDERR, "Error: WordPress bootstrap file not found at {$wpLoadPath}.\n");
23+
exit(2);
24+
}
25+
26+
/**
27+
* advanced-cache.php runs early and expects HTTP server vars.
28+
* In CLI they are usually absent, so provide safe defaults.
29+
*/
30+
if (!isset($_SERVER['REQUEST_METHOD'])) {
31+
$_SERVER['REQUEST_METHOD'] = 'GET';
32+
}
33+
34+
if (!isset($_SERVER['REQUEST_URI'])) {
35+
$_SERVER['REQUEST_URI'] = '/';
36+
}
37+
38+
if (!isset($_SERVER['HTTP_HOST']) || $_SERVER['HTTP_HOST'] === '') {
39+
$host = '';
40+
41+
if (is_file($wpConfigPath) && is_readable($wpConfigPath)) {
42+
$wpConfigContent = file_get_contents($wpConfigPath);
43+
44+
if (is_string($wpConfigContent)) {
45+
if (preg_match("/define\\(\\s*['\\\"]WP_HOME['\\\"]\\s*,\\s*['\\\"]https?:\\/\\/([^'\\\"\\/]+)['\\\"]/i", $wpConfigContent, $matches) === 1) {
46+
$host = $matches[1];
47+
} elseif (preg_match("/define\\(\\s*['\\\"]WP_SITEURL['\\\"]\\s*,\\s*['\\\"]https?:\\/\\/([^'\\\"\\/]+)['\\\"]/i", $wpConfigContent, $matches) === 1) {
48+
$host = $matches[1];
49+
}
50+
}
51+
}
52+
53+
if ($host === '') {
54+
$host = 'localhost';
55+
}
56+
57+
$_SERVER['HTTP_HOST'] = $host;
58+
}
59+
60+
if (!isset($_SERVER['SERVER_NAME']) || $_SERVER['SERVER_NAME'] === '') {
61+
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
62+
}
63+
64+
if (!isset($_SERVER['HTTPS'])) {
65+
$_SERVER['HTTPS'] = 'on';
66+
}
67+
68+
require_once $wpLoadPath;
69+
70+
global $sw_cloudflare_pagecache;
71+
72+
if (!isset($sw_cloudflare_pagecache) || !($sw_cloudflare_pagecache instanceof SW_CLOUDFLARE_PAGECACHE)) {
73+
fwrite(STDERR, "Error: Super Page Cache plugin is not loaded or active in this WordPress install.\n");
74+
exit(3);
75+
}
76+
77+
$purgeResult = $sw_cloudflare_pagecache->get_cache_controller()->purge_all(false, false);
78+
79+
if ($purgeResult === true) {
80+
fwrite(STDOUT, "Cache purged successfully.\n");
81+
exit(0);
82+
}
83+
84+
fwrite(STDERR, "Error: Cache purge failed. Check Super Page Cache logs for details.\n");
85+
exit(4);

0 commit comments

Comments
 (0)