Atticus
Atticus

Reputation: 6720

PHP run a non blocking system call

How can I run a non blocking system call in PHP?

The system call will call a streaming service run by a second PHP script.. So my page sits and waits on this call.

My two thoughts on a solution:

1: There exists a native method / parameter to execute a system call by non blocking

2: Run system() on a new C++ program that will then fork itself and run the actual php script, on a sep. thread

Is there a native method of executing system calls in a non blocking manner or do I need to hack around this...

I currently have shell_exec('nohup php /path/to/file.php &') but it still holds

Upvotes: 6

Views: 5078

Answers (1)

etuardu
etuardu

Reputation: 5536

From PHP manual:

If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

An example is provided in a comment on the same page (linux based):

If you want to start a php process that continues to run independently from apache (with a different parent pid) use nohub. Example:

exec('nohup php process.php > process.out 2> process.err < /dev/null &');

Upvotes: 4

Related Questions