diff --git a/Server/application/command/TaskSchedulerCommand.php b/Server/application/command/TaskSchedulerCommand.php index 0ad3cc48..9cad5c14 100644 --- a/Server/application/command/TaskSchedulerCommand.php +++ b/Server/application/command/TaskSchedulerCommand.php @@ -81,8 +81,12 @@ class TaskSchedulerCommand extends Command return false; } - // 设置日志目录(注意要使用全局函数,避免命名空间影响) - $this->logDir = \runtime_path() . 'log' . DIRECTORY_SEPARATOR; + // 设置日志目录(ThinkPHP5 中无 runtime_path 辅助函数,直接使用 ROOT_PATH/runtime/log) + if (!defined('ROOT_PATH')) { + // CLI 下正常情况下 ROOT_PATH 已在入口脚本 define,这里兜底一次 + define('ROOT_PATH', dirname(__DIR__, 2)); + } + $this->logDir = ROOT_PATH . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR; if (!is_dir($this->logDir)) { mkdir($this->logDir, 0755, true); } @@ -334,7 +338,10 @@ class TaskSchedulerCommand extends Command // 构建命令 // 使用项目根目录下的 think 脚本(同命令行 php think) - $thinkPath = \root_path() . 'think'; + if (!defined('ROOT_PATH')) { + define('ROOT_PATH', dirname(__DIR__, 2)); + } + $thinkPath = ROOT_PATH . DIRECTORY_SEPARATOR . 'think'; $command = "php {$thinkPath} {$task['command']}"; if (!empty($task['options'])) { foreach ($task['options'] as $option) { @@ -360,7 +367,7 @@ class TaskSchedulerCommand extends Command 2 => ['file', $logFile, 'a'], // stderr ]; - $process = @proc_open($command, $descriptorspec, $pipes, root_path()); + $process = @proc_open($command, $descriptorspec, $pipes, ROOT_PATH); if (is_resource($process)) { // 关闭管道