[英]Can't run Laravel Envoy with exec (works in command line but doesn't with Artisan::call)
I have an envoy script which I am triggering within Laravel Command.我有一个特使脚本,我在 Laravel 命令中触发。
php artisan proxy:update
public function handle() {
exec("envoy run update");
}
If I run this on command line as php artisan proxy:update
, it works.如果我在命令行上以
php artisan proxy:update
运行它,它就可以工作。
However if I run this inside my Laravel app as Artisan::call('proxy:configure');
但是,如果我在我的 Laravel 应用程序中作为
Artisan::call('proxy:configure');
运行它it doesn't work.它不起作用。
In console whoami
= vagrant;在控制台中
whoami
= vagrant; likewise in my command exec('whoami')
is also vagrant.同样在我的命令
exec('whoami')
中也是 vagrant。
If I change it to如果我将其更改为
$out = shell_exec('envoy run update');
dd($out);
In command-line it shows the output, but with Artisan::call()
, it returns empty string.在命令行中显示 output,但使用
Artisan::call()
时,它返回空字符串。
What might be the issue for being able to use exec()
with artisan command?能够将
exec()
与 artisan 命令一起使用可能是什么问题?
As far as I understand, php-fpm was blocking it.据我了解,php-fpm 阻止了它。 I tried using Symfony's Process instead of
exec()
and I was getting "terminated".我尝试使用 Symfony 的 Process 而不是
exec()
并且我被“终止”了。 Then I moved Artisan::call()
to Artisan::queue()
and it worked.然后我将
Artisan::call()
移动到Artisan::queue()
并且它起作用了。 I'd be happy to know if anyone has any other explanations.我很高兴知道是否有人有任何其他解释。
Update: I created a queue that is run by deployer
user which has sudo privileges (normally www-data run my queues).更新:我创建了一个由具有 sudo 权限的
deployer
用户运行的队列(通常 www-data 运行我的队列)。 Now it works perfectly.现在它完美地工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.