Forking in PHP on Windows Forking in PHP on Windows windows windows

Forking in PHP on Windows


how about installing psexec and use the -d (don't wait) option

exec('psexec -d php-cgi.exe somescript.php');


Get PSExec and run the command:

exec("psexec -d php-cgi.exe myfile.php");


PSTools are a good patch in, but I'll leave this here:
If your server runs windows 10 and it has the latest updates, you can install a Linux subsystem, which has its own Kernel that supports native forking.This is supported by Microsoft officially.

Here's a good guide on how to do it.

Once you've installed the subsystem itself, you need to install php on the subsystem.

Your windows "c:\" drive can be found under "/mnt/c", so you can run your php from the subsystem, which supports forking (and by extension the subsystem's php can use pcntl_fork).

Example: php /mnt/c/xampp/htdocs/test.php

If you want to run the subsystem's php directly from a windows command line you can simply use the "wsl" command.

Assuming you're running this from under "C:\xampp\htdocs\"
Example: wsl php main.php

The "wsl" command will resolve the path for you, so you don't need to do any dark magic, if you call the command under c:\xampp\htdocs, the subsystem will resolve it as "/mnt/c/xampp/htdocs/".

If you're running your server as an apache server, you don't really need to do anything extra, just stop the windows apache server and start the linux one and you're done.Obviously you'll need to install all the missing php modules that you need on the subsystem.