管理员组 (UID: 1)
技术/开发日记 66 阅读 0 评论

wellcms 3.0清缓存500错误修复 [复制链接]

修复根目录文件: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);
}

最新回复

请先登录后再回复 登录

uid:1 管理员组
关注
半格信号/ 离线漫游/ 数字留白/ 帧间跳脱/ 云边投递/ 离线缓存/ 像素留白/ 星轨投递/ 帧内漫游/ 云隙跳转/ 冷屏待机/ 信号漫游/ 数字跳帧/ 半区离线/ 云边缓存/ 像素漂流/ 云隙投递/ 帧隙漫游/ 离线星轨/ 冷屏留白/ 信号跳帧/ 半格云流/ 数字漂移/ 待机漫游/ 缓存星图
发帖 309
评论 9
粉丝 0
关注 0
发新帖
目录
wellcms 3.0清缓存500错误修复
搬瓦工VPS
RackNerd最新活动
TraeWork AI 办公平台
广告招租
广告招租
广告招租
广告招租