RE: Execute a php page and don't wait for it to finish

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Sebastian Detert [mailto:php-maillist@xxxxxxxxx]
> Sent: Tuesday, October 19, 2010 6:51 AM
> To: Ferdi; PHP General
> Subject: Re:  Execute a php page and don't wait for it to finish
> 
> Ferdi schrieb:
> > Hi List,
> >
> > I have a php page that updates data from one database to another when
> > it is run.
> > My query is, how can I trigger the execution of this update page from
> > another php / javascript without the calling page having to wait for
> > the update page to finish?
> > Basically, I think the update page needs to use:
> > ignore_user_abort(1);
> > set_time_limit(0); // I don't think the script will take more than 1
min.
> >
> > At the other end I found this:
> > 1)
> > http://www.mindraven.com/blog/php/run-a-php-script-in-the-
> background-u
> > sing-ajax/
> > 2) On that page a user suggested using *pclose(popen('/usr/bin/php
> > /path/to/something.php > /dev/null &', 'r')*
> > *    *However, I need this to be usable on windows servers also.
> > 3) Finally, would pcntl_exec, pcntl_fork, exec or something be useful
> > for me?
> >
> > Which of the above 3 options is the better one?
> > Other suggestions are welcome :)
> >
> > Thanks and Regards,
> > Ferdi
> >
> >
> 1) I guess an asynchronous ajax request is what you are looking for. But
it
> won't work on command line.
> 
> 2) Maybe
> http://robert.accettura.com/blog/2006/09/14/asynchronous-processing-
> with-php/
> could help you, but I never tried that.
> 

What about having the script flags a field in the DB and have another script
running as daemon either via cron or Windows Service/Scheduler and run the
command based on the flag in the DB?  This way, you don't have to worry
about the security issues of *pclose(popen('/usr/bin/php > >
/path/to/something.php > /dev/null &', 'r')*

You can also have another page that will flag the DB should the user wish to
abort the command.  The background script would check this abort flag so
often based on your criteria and abort the corresponding command
accordingly, especially if some of the command may run for extended period
time.

Regards,
Tommy


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux