1

When we using Symfony\Component\Process\Process, the command run as who?

I tried the command whoami through Process, but it return void???

$return = exec('whoami');
echo $return."\n"; // return [myname]
$process = new Process('whoami'); // The symfony process
echo $process->getOutput(); // return nothing @_@
luchaninov
  • 6,792
  • 6
  • 60
  • 75
GusDeCooL
  • 5,639
  • 17
  • 68
  • 102

3 Answers3

3

Yes, it runs as user you run this command or the user of your webserver. Your code seems a bit incomplete. I suggest adding $process->run(); before trying to get an output.

Ziumin
  • 4,800
  • 1
  • 27
  • 34
0

I almost guarantee that that Process runs as whatever user your webserver is running as. If you're running apache for instance, try running:

ps aux | egrep '(apache|httpd)'

In your terminal to discover which user apache is running as. My money would be on either apache or httpd as the user which Process runs under. Hope that helps.

Nicholas Byfleet
  • 581
  • 3
  • 15
0

From the documentation is better use start() instead run() if you want to create a background process. The process_max_time could kill your process if you create it with run()

"Instead of using run() to execute a process, you can start() it: run() is blocking and waits for the process to finish, start() creates a background process."

Freenando
  • 405
  • 7
  • 16