在后台运行脚本(shell_exec)在composer/PHP-DI函数上失败
我手动运行脚本,一切正常在后台运行脚本(shell_exec)在composer/PHP-DI函数上失败,php,Php,我手动运行脚本,一切正常 $container = require '../config/bootstrap.php'; try { $test = $container->get(Test::class); $test->run(); } catch(\Exception $e) { echo $e->getMessage() . "\n"; die; } 但当我从另一个文件
$container = require '../config/bootstrap.php';
try {
$test = $container->get(Test::class);
$test->run();
}
catch(\Exception $e) {
echo $e->getMessage() . "\n";
die;
}
但当我从另一个文件夹调用该文件时,如下所示:
$script = __DIR__ .'/folder/test-service.php';
$output = shell_exec('php '.$script);
var_dump($output);
我得到以下错误:
致命错误:require():无法在第13行的/anotherFolder/folder/test-service.php中打开所需的“../config/bootstrap.php”(include_path=.”:')
而且在那之后,我得到了很多错误,文件不存在
php包括php-DI的类映射
需要“../vendor/autoload.php”
use DI\ContainerBuilder;
$containerBuilder = new ContainerBuilder;
$containerBuilder->addDefinitions(__DIR__ . '/config.php');
$container = $containerBuilder->build();
return $container;
require
指令与当前目录相关
您可以将该行替换为require _DIR _.'/../config/bootstrap.php'代码>