修复根目录文件:xxx.com\bin\warmup-compile.php
<?php
declare(strict_types=1);
/**
* bin/warmup-compile.php
* 单进程重建 WellCMS 编译缓存(含 DI 容器)。
*
* 背景:后台“清除缓存”后,php-cgi 多个工作进程会并发重编译同一批 PHP 文件,
* Compile.php 压缩时使用的共享临时文件 php_{md5}.tmp 存在竞态,可能写出 0 字节
* 缓存文件;生产模式(DEBUG=0)下 Compile::include() 直接信任已存在的缓存,
* 导致 "Interface ... not found" / 500 且无法自愈。
*
* 用法(清缓存后立即执行一次):
* D:\ServBay\bin\php.cmd D:\ServBay\www\vpsbj.com\bin\warmup-compile.php
*/
define('APP_PATH', str_replace('\\', DIRECTORY_SEPARATOR, dirname(__DIR__)) . DIRECTORY_SEPARATOR);
define('IN_WELLCMS', true);
define('DEBUG', 0);
require APP_PATH . 'app/Core/Compile.php';
require APP_PATH . 'app/Core/Autoload.php';
$containerCache = APP_PATH . 'storage/tmp/container.php';
// 1. 初始化:重建清单、资源聚合、DI 容器(单进程无竞态)
App\Core\Compile::init($containerCache);
echo "[1/2] Compile::init 完成(manifest/assets/container)\n";
// 2. 预热所有 PHP 类文件的编译缓存(app/ src/ plugins/),避免线上懒加载竞态
$roots = ['app', 'src', 'plugins'];
$total = 0;
$failed = [];
foreach ($roots as $root) {
$dir = APP_PATH . $root;
if (!is_dir($dir)) continue;
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS)
);
foreach ($it as $f) {
if (!$f->isFile() || strtolower($f->getExtension()) !== 'php') continue;
try {
App\Core\Compile::include($f->getPathname());
$total++;
} catch (\Throwable $e) {
// 个别源文件的注释里含有 <template include="..."> 示例(如 Compile.php 自身),
// 会被编译器误当作模板标签解析;运行时这些文件走直接 require,不经过编译缓存
$failed[] = $f->getPathname() . ' => ' . $e->getMessage();
}
}
}
echo "[2/2] 预热编译 {$total} 个 PHP 文件,跳过 " . count($failed) . " 个异常文件\n";
foreach ($failed as $line) echo " SKIP: {$line}\n";
echo $containerCache . (file_exists($containerCache) ? " 已生成 ✓" : " 缺失 ✗") . "\n";
if (defined('STDERR') && !file_exists($containerCache)) {
fwrite(STDERR, "容器缓存未生成,请检查上方报错\n");
exit(1);
}



