我正在尝试使用 Symfony Process 组件执行 Symfony 命令,以便在获取 API 请求时异步执行。
当我这样做时,我会收到错误消息Code: 127(Command not found)
,但是当我从控制台手动运行它时,它就像一个魅力。
这是电话:
public function asyncTriggerExportWitnesses(): bool
{
$process = new Process(['php /var/www/bin/console app:excel:witness']);
$process->setTimeout(600);
$process->setOptions(['create_new_console' => true]);
$process->start();
$this->logInfo('pid witness export: ' . $process->getPid());
if (!$process->isSuccessful()) {
$this->logError('async witness export failed: ' . $process->getErrorOutput());
throw new ProcessFailedException($process);
}
return true;
}
这是我得到的错误:
The command \"'php /var/www/bin/console app:excel:witness'\" failed.
Exit Code: 127(Command not found)
Working directory: /var/www/public
Output:================
Error Output:================
sh: exec: line 1: php /var/www/bin/console app:excel:witness: not found
我对 Process 组件的使用有什么问题?
像这样调用它也不起作用:
$process = new Process(['/usr/local/bin/php', '/var/www/bin/console', 'app:excel:witness']);
这会导致以下错误:
The command \"'/usr/local/bin/php' '/var/www/bin/console' 'app:excel:witness'\" failed.
Exit Code: ()
Working directory: /var/www/public
Output:
================
Error Output:
================