By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,889 Members | 1,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,889 IT Pros & Developers. It's quick & easy.

Launching a background script from php in Windows/IIS

P: n/a
Bob
Hi,

I'm trying to build a PHP page which launches another php script to be run
in the background. The web page should return immediately, while the
background script may run for 10 minutes or something. Unfortunately I'm
getting all kinds of weird behaviour..

In my main script I'm using exec() (also tried the other options) to start a
..bat file. This actually works, the batch file is launched and is able to
write something to disk.. Now if I put the following line in the batch file:

c:\php\php.exe -q backgroundscript.php

then instantly I'm seeing about 30 php.exe processes being created, but
nothing seems to be happening really. The processes seem to be dying
immediately and replaced by new ones. So apparently php is trying something
but fails and tries again.

Both the script and the batch file work fine from the command line. Group
'Everyone' has read/execute rights for the batch file, the php script and
php.exe. I have tried prefixing the command with START /b or cmd.exe /c but
neither seem to make any difference. Also I tried redirecting stderr, stdout
and stdin to NUL

Server is Win2k, IIS5, php4.3.0. Searched the php docs, tried suggestions
but it doesn't work, maybe because they use Apache.

My guess is that the anonymous user IUSR_* doesn't have the rights to do
something, but I can't figure out what. Please help me if you have an idea..

Bob
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Bob" <no****@nospam.com> wrote in message
news:<bj**********@news.cistron.nl>...

I'm trying to build a PHP page which launches another php script
to be run in the background. .... Now if I put the following line in the batch file:

c:\php\php.exe -q backgroundscript.php


....you would be launching the wrong interpreter. The command-line
interpreter on Windows is not c:\php\php.exe, but, rather,
c:\php\cli\php.exe

Cheers,
NC
Jul 16 '05 #2

P: n/a
Bob
Nikolai,

Thanks alot, you saved my day!

I still had trouble to run the script in the background, PHP seemed to
insist on waiting for the background script to terminate. Finally got it
working by following this comment in the php docs:

# I used the bgrun-exe (www.jukkis.net/bgrun/bgrun.exe) to get this
working.
# I just put this file in my php directory (d:\php)
# This is my start.php file:
# $tmp=exec("d:\php\bgrun d:\php\cli\php -q d:\www\myphpapp.php
nul",$res);
Bob

"Nikolai Chuvakhin" <nc@iname.com> wrote in message
news:32**************************@posting.google.c om... "Bob" <no****@nospam.com> wrote in message
news:<bj**********@news.cistron.nl>...

I'm trying to build a PHP page which launches another php script
to be run in the background.

...
Now if I put the following line in the batch file:

c:\php\php.exe -q backgroundscript.php


...you would be launching the wrong interpreter. The command-line
interpreter on Windows is not c:\php\php.exe, but, rather,
c:\php\cli\php.exe

Cheers,
NC

Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.