How to Use Shell_Exec Without Waiting For the Command to Complete

shell_exec without waiting for the output

This has been answered before at Asynchronous shell exec in PHP

Briefly:

shell_exec( $your_command . "> /dev/null 2>/dev/null &" );

Is there a way to use shell_exec without waiting for the command to complete?

How about adding.

"> /dev/null 2>/dev/null &"

shell_exec('php measurePerformance.php 47 844 email@yahoo.com > /dev/null 2>/dev/null &');

Note this also gets rid of the stdio and stderr.

shell_exec without waiting for the output

This has been answered before at Asynchronous shell exec in PHP

Briefly:

shell_exec( $your_command . "> /dev/null 2>/dev/null &" );

PHP execute command and log output without waiting

On Linux you can do:

exec('command* > /dev/null 2>/dev/null &');

On Windows you can do:

pclose(popen('start /B cmd /C "command* >NUL 2>NUL"', 'r'));

Both examples disable output and errors, those go to /dev/null (linux) or NUL (windows) which means they are stored "nowhere".

You can replace these with valid paths on your system.

On Linux, a & at the end places it into background. On windows this is more complicated and needs start to invoke the process and cmd to allow redirection of the streams.

PHP Exec: Without Waiting, Without Discarding the Output, Without nohup

Add an ampersand to the end of the command, so:

exec('dosomething > saveit.txt &');

Is there a way to use shell_exec without waiting for the command to complete?

How about adding.

"> /dev/null 2>/dev/null &"

shell_exec('php measurePerformance.php 47 844 email@yahoo.com > /dev/null 2>/dev/null &');

Note this also gets rid of the stdio and stderr.

Execute another PHP file without waiting for it to finish its execution

This should help you - Asynchronous shell exec in PHP

Basically, you shell_exec("php Server.php > /dev/null 2>/dev/null &")



Related Topics



Leave a reply



Submit