Re: Re: asynchronous launch of a script
| From: | Stuart Dallas | Date: | Mon, 27 Jun 2011 10:39:39 +0000 |
| Subject: | Re: Re: asynchronous launch of a script | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313746@lists.php.net to get a copy of this message | ||
On Monday, 27 June 2011 at 07:10, Tamara Temple wrote:
>
> On Jun 26, 2011, at 11:52 PM, Jim Lucas wrote:
>
> > On 6/26/2011 7:58 PM, Jim Giner wrote:
> > > You mean - you want a second thread to run independently of your
> > > current
> > > "running" script? A wonderful thing to do and helpful for long
> > > intenesive
> > > processes but do you really want to go thru the hassles of managing
> > > two
> > > processes? Won't you have to verify the results of your offshoot
> > > and react
> > > to unexpected circumstances? Otherwise, what are you doing that
> > > would not
> > > require such complex management?
> >
> > Having an OpenBSD server I use a thing called nohup.
> >
> > I have a shell script that starts/stops things for me
> >
> > nohup /usr/bin/ssh -2 -N -f -L $L_IP:$L_PORT:$R_IP:$R_PORT
> > root@localhost 1>/dev/null
> >
> > This starts a ssh tunnel port forwarding for me with a from and to
> > port assignment.
> >
> > But, one crucial thing you haven't told us is what OS you are trying
> > to do this on.
> Wow, that's really getting complex. All I want is for a php script to
> get launched and the calling script to return immediately. I don't
> necessarily have to know or care when the called script ends, just
> want the user to get an immediate return instead of waiting around for
> the lengthy script to run. I'm not talking AJAX or anything like that
> where the page depends on the eventual output from the called script.
In my experience it's best to separate the processes and pass jobs to be done via a database,
IPC, socket or other mechanism from the HTTP handler to the offline process. I use a job queueing
system to accomplish this in most of my projects, where I can either schedule a repeating job or
queue one-off jobs when needed. I wrote a post on my blog a little while ago describing that
system...
http://stut.net/2009/05/29/php-job-queue/
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/