[nycphp-talk] WAMP (minus the M) forking question - also open to other ideas
Elijah Insua
tmpvar at gmail.com
Tue Apr 28 15:46:22 EDT 2009
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 <jcampbell1 at 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
> <michaelforte at 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: michaelforte at 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20090428/e1413934/attachment.html>
More information about the talk
mailing list