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

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.


This will execute a command and disconnect from the running process. Of course, it can be any command you want. But for a test, you can create a php file with a sleep(20) command it.

exec("nohup /usr/bin/php -f sleep.php > /dev/null 2>&1 &");


You can also give your output back to the client instantly and continue processing your PHP code afterwards.

This is the method I am using for long-waiting Ajax calls which would not have any effect on client side:

ob_end_clean();ignore_user_abort();ob_start();header("Connection: close");echo json_encode($out);header("Content-Length: " . ob_get_length());ob_end_flush();flush();// execute your command here. client will not wait for response, it already has one above.

You can find the detailed explanation here: http://oytun.co/response-now-process-later