Forking PHP on Windows 2003.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
We are attempting to fork a php script into a background php script and
have the first scrip continue to completion. Is this even possible in
the windows version of php? We have used the many code snippets
floating around on the Internet claiming to fork on Windows, yet we
never get it to work properly, sometimes ending up with hunderds of
dead php.exe processes on the machine.

Our environment is:

Windows 2k3 server
PHP 4.3.6 (cgi-fcgi) (built: Apr 14 2004 17:21:37)

If there is any other info needed to determine the problem I'll gladly
reply with it.

All assistance is appreciated.

Re: Forking PHP on Windows 2003.

Hopeless A wrote:
Quoted text here. Click to load it

Yes, if Windows itself allows it.  You probably tried something
along the lines of:

exec('start C:\php\cli\php.exe C:\inetpub\wwwroot\background.php');

However, if you type HELP START from your Windows command prompt,
you may notice this bit:

If Command Extensions are enabled, external command
invocation through the command line or the START command
changes as follows:


When executing an application that is a 32-bit GUI
application, CMD.EXE does not wait for the application
to terminate before returning to the command prompt.
This new behavior does NOT occur if executing within
a command script.

My guess is that you have Command Extensions enabled, so
forking doesn't work.  Try this:

exec('start cmd /E:OFF /C C:\php\cli\php.exe ' .

The /E:OFF switch will disable Command Extensions for the
duration of this command-line session, while the /C switch
will make sure the session will terminate after it's

Quoted text here. Click to load it

Are you sure you are using the correct php.exe?  Rememeber,
there are two files named php.exe in PHP distribution,
the CGI executable (usually located in PHP root folder)
and the command-line interpreter (usually located in the
/CLI subfolder)...


Re: Forking PHP on Windows 2003.

Some progress but now i'm getting:

Warning: exec() [function.exec]: Unable to fork [start cmd /E:OFF /C

Re: Forking PHP on Windows 2003.

Quoted text here. Click to load it

Try the AT command.

Re: Forking PHP on Windows 2003.

NC / Chung,

Thanks for the assist. What was causing the error was the script must
run as a user that has the ability to interact with the OS.

Hopeless A

Site Timeline