0

I used Laravel for my framework and build script by Laravel command (Artisan) / (Symfony/process)

In my method, I used the command ps -f | grep node to find my all-node process pid.

I try to run this command to the terminal - running well method have a return perfectly - use the root user

but when i used controller and call by request url, my method can't return (absolutly "") / NULL -> runing with php / use _www/ apache user

use Symfony\Component\Process\Process;

$f='ps -f | greb node';
$processFind =  Process::fromShellCommandline($f);
$processFind->run();
dd($processFind->getOutput());
Hedayatullah Sarwary
  • 2,664
  • 3
  • 24
  • 38
yuanganteng
  • 171
  • 9

1 Answers1

1
use Illuminate\Support\Facades\Artisan;

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

    //
});

Just like that Artisan::call('your_command_you_call_in_terminal_withour_php_artisan');

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

flakerimi
  • 2,580
  • 3
  • 29
  • 49
  • Its not for calling artisan, but how to run command bash with php as root user. – yuanganteng Aug 03 '21 at 04:45
  • 1
    Thats a different question but check this https://stackoverflow.com/questions/10915241/how-to-run-from-php-a-bash-script-under-root-user/10915397 – flakerimi Aug 03 '21 at 12:00
  • Thanks that my mind. That my questions. How to run artisan use root user event call by controller used artisan::cal. That ab – yuanganteng Aug 04 '21 at 05:47