Execute another PHP file without waiting for its completion.

I have a StartServer.php file that basically starts the server if it is not already running. Everything works fine, except that StartServer.php will wait forever for the shell_exec () 'd server.php file to finish executing, which it never does.

Is there a way to execute a PHP file and just forget about it - and not wait for it to complete?

Edit: It should work on Windows and Linux.

+3
source share
3 answers

This should help you - Asynchronous exec shell in PHP

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

+3
source

- pcntl. , Windows -. , , exec ( ), , . , pcntl ( , Linux). script . / PHP, -.

0

, , .. "daemonize", , script . , , daemon.

, PHP, . :

posix_setsid(); //Start a new session
if(pcntl_fork()) {exit();} //Fork process and kill the old one

I think this works on Windows as well. (Not tested.)

0
source

Source: https://habr.com/ru/post/1765498/


All Articles