Launching a background script from php in Windows/IIS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob

    Launching a background script from php in Windows/IIS

    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 backgroundscrip t.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


  • Nikolai Chuvakhin

    #2
    Re: Launching a background script from php in Windows/IIS

    "Bob" <nospam@nospam. com> wrote in message
    news:<bji9ti$lc d$1@news.cistro n.nl>...[color=blue]
    >
    > I'm trying to build a PHP page which launches another php script
    > to be run in the background.[/color]
    ....[color=blue]
    > Now if I put the following line in the batch file:
    >
    > c:\php\php.exe -q backgroundscrip t.php[/color]

    ....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

    Comment

    • Bob

      #3
      Re: Launching a background script from php in Windows/IIS

      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:\p hp\bgrun d:\php\cli\php -q d:\www\myphpapp .php[color=blue]
      >nul",$res);[/color]

      Bob



      "Nikolai Chuvakhin" <nc@iname.com > wrote in message
      news:32d7a63c.0 309081359.5562d 99c@posting.goo gle.com...[color=blue]
      > "Bob" <nospam@nospam. com> wrote in message
      > news:<bji9ti$lc d$1@news.cistro n.nl>...[color=green]
      > >
      > > I'm trying to build a PHP page which launches another php script
      > > to be run in the background.[/color]
      > ...[color=green]
      > > Now if I put the following line in the batch file:
      > >
      > > c:\php\php.exe -q backgroundscrip t.php[/color]
      >
      > ...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[/color]


      Comment

      Working...