简体   繁体   English

无法使用 exec 运行 Laravel Envoy(在命令行中工作,但不适用于 Artisan::call)

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM