【问题标题】:Artisan runing command ps -f | grep nodeArtisan 运行命令 ps -ef | grep 节点
【发布时间】:2021-10-08 05:35:13
【问题描述】:

我将 Laravel 用于我的框架并通过 Laravel 命令 (Artisan) / (Symfony/process) 构建脚本

在我的方法中,我使用命令ps -f | grep node 来查找我的全节点进程pid。

我尝试将此命令运行到终端-运行良好的方法完美返回-使用root用户

但是当我使用控制器并通过请求 url 调用时,我的方法无法返回(绝对“”)/NULL -> 使用 php 运行/使用 _www/apache 用户

use Symfony\Component\Process\Process;

$f='ps -f | greb node';
$processFind =  Process::fromShellCommandline($f);
$processFind->run();
dd($processFind->getOutput());

【问题讨论】:

  • 为什么不在控制器中使用 Artisan::call of you 命令

标签: php laravel laravel-artisan symfony-process


【解决方案1】:
use Illuminate\Support\Facades\Artisan;

Route::post('/user/{user}/mail', function ($user) {
    $exitCode = Artisan::call('mail:send', [
        'user' => $user, '--queue' => 'default'
    ]);

    //
});

就这样 Artisan::call('your_command_you_call_in_terminal_withour_php_artisan');

https://laravel.com/docs/5.2/artisan#calling-commands-via-code

【讨论】:

  • 它不是为了调用工匠,而是如何以 php 作为 root 用户运行命令 bash。
  • 这是一个不同的问题,但请查看stackoverflow.com/questions/10915241/…
  • 感谢我的想法。那是我的问题。如何通过控制器使用 artisan::cal 运行 artisan 使用 root 用户事件调用。那个ab
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-03
  • 1970-01-01
  • 2022-01-23
  • 1970-01-01
  • 2016-09-11
  • 2016-09-07
  • 2017-05-27
相关资源
最近更新 更多