Hi John and Elijah,

Thank you for the input. I spent most of the night trying to get this to work and determined the following:

- START /B does not appear to work.

- pclose(popen($cmd)); still hangs the parent

- I found COM(Wscript.Shell) ... $->Run(...) on the web but could not get it working. It would spawn a cmd.exe but would not run the rest of the command.
The cmd.exe child would not die. If I ran the same command from Start > Run it would work just fine.

$WshShell = new COM(Wscript.Shell);
$oRun = $WshShell->Run("cmd /C php.exe -f child.php");

- As a last resort I was going to compile Elijah's C code but was really hoping there would be a built-in method. I might still end up using it in the end.

- Found COM(Wscript.Shell) ... $->Exec() on MSDN and it worked! I have to give the full path to the exe and script as environmental variables are not available.


All in all, I have no clue if COM ... ->Exec() is the best way to do this, if it is secure, or why COM .. ->Run() did not work. I have not used COM much and found it hard to wade through the doc at php.net. Ultimately, I have learned that it would be much nicer if you could simply fork in Windows as you can in *nix.

If there are any other suggestions out there, please let me know! I am all ears and trying to learn.

Thank you for the support!

Michael J. Forte

Web Designer, WR Web Designs
Webmaster, Town of LaFayette
Software Engineer, IBM

Education: Clarkson University Alum (2005) :: Resume
E-mail: michaelfo...@hotmail.com

"Often those who work the hardest are the luckiest..."


Elijah Insua wrote:
Here is some C code I had laying around which executes a detached process, much like
START.

#include <windows.h>
#include <process.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    if (argc < 2)
    {
        printf("Fork32 v1.0 - A windows process splitter\n\n");
        printf("Usage: fork32.exe C:\\full\\path\\to\\application.exe");
        return 0;
    }
   
    _spawnl( _P_DETACH, argv[2], NULL);
    return 1;
}

hope it helps
-- Elijah

On Tue, Apr 28, 2009 at 12:42 AM, John Campbell <jcampbe...@gmail.com> wrote:
A quick google search for "windows run process in background" yielded:

"In case anyone has this problem in future, I finally found out the
solution. The START command in Windows command line allows you to
start another command window running any command; and the /B option
can start the command without the extra command window, so you get
similar behavior to Unix's background processes. Look it up for more
details."

I don't use windows, but I trigger background processes with and "&"
in *nix, and it looks like windows offers the same functionality with
"start /b"

regards,
John Campbell


On Tue, Apr 28, 2009 at 12:16 AM, Michael J. Forte
<michaelfo...@hotmail.com> wrote:
> Hi experienced and talented community of which I have been trolling for a
> few years!
>
> I have a question for all of you and I hope this makes sense.
>
> First, the background. I am coding a PHP Web application that has to call a
> external program, however, because only one instance of the program can be
> ran at a time I need to implement a queue. In addition, it is important the
> users need to not wait (keep the browser open) for their job to process. The
> script will send them an e-mail with a link after their job completes. This
> means I need something to persistently run whenever there is something in
> the queue. In summary: front end script calls secondary child which runs
> until queue is empty by calling external program.
>
> My problem is, I cannot figure out how to properly fork under Windows,
> allowing the parent script to run to completion, and not hang the browser
> waiting for the child to complete. I am at the point where I can spawn the
> child and it will run even when the parent browser is closed but will not
> release the parent script until it completes. I have tried exec(), system(),
> shell_exec(), popen(), and a COM call (which I might have done wrong). Each
> of those called php -f childScript.php.
>
> I thought about a few other alternatives:
>
> 1. Use a scheduled task to check for a queue at a set interval. This is the
> least desired solution as it could cause unwanted delay.
> 2. Write a PHP daemon/Win32 service to monitor a queue of which could be
> queried and started if needed by parent script and it would run until the
> queue is empty at which time it would shutdown.
> 3. Write a Perl script to be called by the parent which would fork and call
> the secondary PHP script, subsequently terminating and releasing the parent
> PHP script.
>
> In summary:
>
> - WAMP environment, cannot use Linux as external program is Windows only
> (BUMMER!)
> - Need a queue to handle calls to an external program, currently stored in a
> flat file
> - Parent script needs to fork to a child script which can run independent of
> the parent until queue is empty
> - Parent script needs to be able to complete prior to child completing
> - Because of time required to run a job and because of the potential for
> many users, users need to be able to submit'n'run.
>
> Do any of you PHP gods (and goddesses!) have any thoughts on how to fork
> under Windows, how to handle this situation, or alternatives? Should I be
> using some other language? Perl, AJAX, other?
>
> Google (or my search string) was less than helpful.
>
> --
> Thank you,
> Michael J. Forte
> Web Designer, WR Web Designs
> Webmaster, Town of LaFayette
> Software Engineer, IBM
>
> Education: Clarkson University Alum (2005) :: Resume
> E-mail: michaelfo...@hotmail.com
>
> "Often those who work the hardest are the luckiest..."
> _______________________________________________
> New York PHP User Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/show_participation.php
>
_______________________________________________
New York PHP User Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/show_participation.php


_______________________________________________ New York PHP User Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/show_participation.php
_______________________________________________
New York PHP User Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/show_participation.php

Reply via email to