tags:

views:

477

answers:

2

We are running PHP on a Windows server (a source of many problems indeed, but migrating is not an option currently). There are a few points where a user-initiated action will need to kick off a few things that take a while and about which the user doesn't need to know if they succeed or fail, such as sending off an email or making sure some third-party accounts are updated. If I could just fork with pcntl_fork(), this would be very simple, but the PCNTL functions are not available in Windows.

It seems the closest I can get is to do something of this nature:

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

However, this would be far more complicated. The actions I need to kick off rely on a lot of context that already will exist in the running process; to use the above example, I'd need to figure out the essential data and supply it to the new script in some way. If I could fork, it'd just be a matter of letting the parent process return early, leaving the child to work on a few more things.

I've found a few people talking about their own work in getting various PCNTL functions compiled on Windows, but none seemed to have anything available (broken links, etc).

Despite this question having practically the same name as mine, it seems the problem was more execution timeout than needing to fork. So, is my best option to just refactor a bit to deal with calling php-cgi, or are there other options?

Edit: It seems exec() won't work for this, at least not without me figuring some other aspect of it, as it waits until the call returns. I figured I could use START, sort of like exec( 'start php-cgi.exe somescript.php' );, but it still waits until the other script finishes.

+3  A: 

how about installing psexec and use it's -d (don't wait) option
exec( 'psexec -d php-cgi.exe somescript.php' );

jah
Excellent, I got that to work. I'm confused by why exec'ing with `start` wasn't able to do what I needed. Also, I needed to call psexec with the -accepteula parameter, even though I had already manually accepted it running it myself on the server.
Doug Kavendek
A: 

Get PSExec and run the command:

exec("psexec -d php-cgi.exe myfile.php");
JonnyLitt
read the other answers JonnyLitt!
jah