0

我正在尝试在我的共享托管服务器上的 Laravel 应用程序中使用 Symfony 启动一个进程,该进程将调用带有如下参数的 Artisan 命令:

$process = new Process(['/usr/local/bin/php', base_path('artisan'), 'queue:work --stop-when-empty']);
$process->setTimeout(null);
$process->start();

这不起作用,因为我得到:

ERROR: Command "queue:work --stop-when-empty" is not defined.

Did you mean one of these?
    queue:batches-table
    queue:clear
    queue:failed
    queue:failed-table
    queue:flush
    queue:forget
    queue:listen
    queue:monitor
    queue:prune-batches
    queue:prune-failed
    queue:restart
    queue:retry
    queue:retry-batch
    queue:table
    queue:work {"exception":"[object] (Symfony\\Component\\Console\\Exception\\CommandNotFoundException(code: 0): Command \"queue:work --stop-when-empty\" is not defined.

问题在于参数--stop-when-empty,因为命令在没有它的情况下成功运行。如何将此参数传递给命令?

4

1 回答 1

2

该过程在您传入的每个数组值周围添加引号。现在,它正在尝试运行

"exec '/usr/local/bin/php' '/your/path/to/artisan' 'queue:work --stop-when-empty'"

因此,通过在整个字符串周围添加引号,它被'queue:work --stop-when-empty'视为单个命令,而不是命令和选项。将命令分开,以便正确引用它

$process = new Process(['/usr/local/bin/php', base_path('artisan'), 'queue:work', '--stop-when-empty']);
于 2021-12-22T16:39:24.110 回答