You are here: Re: running an exec in the background, let page go on. « All PHP « IT news, forums, messages
Re: running an exec in the background, let page go on.

Posted by Jamie on 09/28/77 11:46

In <1146151998.974850.183860@g10g2000cwb.googlegroups.com>,
"news@celticbear.com" <news@celticbear.com> mentions:
>I need it to do the Zip and FTP in the background and let the page
>finish, otherwise the user could have that page sitting there loading
>for 20 minutes while the FTP completes.
>
>Here's what I have:
>
>$zipfile = $order_po.".zip";
>exec("/var/www/html/services/ftp.sh $zipfile 2>&1 &", $output2,
>$status);
>echo "<div align='center' class='style1_hd'>Your auto-created ZIP file
>is currently being sent through FTP!</div></body></html>";
>exit();
>?>

If it's the kind of thing that DOESN'T need to be distributed and
it it's a UNIX based host..

I would take a page from the cron suggestion, but, attempt to run it
through the 'batch' command. (On some hosts, batch is run from cron, the
two are kind of related)

Batch will handle all the nitty gritty about emailing you when it's done, etc..
Plus, it's nice to the system, waiting for a time when the machine isn't doing
a whole lot to run the commands. I use batch a LOT for this kind of thing.
(forking processes that need to "go away" when done) Easy on the system, no
worries about zombie processes or signal handlers, etc...

Problem: Batch might not like to be run as user 'nobody' so you
may have to pull some tricks to get around that. This is doable
with set-ID, but, it's less then ideal.

Unfortunately, batch one of those commands that is not well utilized.

If you can get it to work, batch is by far the best, since it won't be
connected to the web server in any way.

Lets hear it for batch! :-)

If it does need to be distributed or batch won't work, you can do
it in perl, and call on the fork() method (after closing stdio)

Or, just redirect stdio to and from /dev/null Forking in apache
is tricky business, especially when mysql handles are open and
such.

Jamie
--
http://www.geniegate.com Custom web programming
guhzo_42@lnubb.pbz (rot13) User Management Solutions

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация