Re: [PHP] Background Processing
- Original Message - From: Richard Perez [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, April 24, 2002 4:32 PM Subject: [PHP] Background Processing Hi people!! I'm trying to find a way to handle this but I don't come up with anything. I need to execute a query to a DB using PHP. The thing is that the query takes 0.5 hours to execute and I can't wait that time with the browser opened in that page. What I want to do is to execute a PHP code block in some sort of background way so I can execute the query and send the results via email. Any ideas to do this?? Thanks a lot. Richard. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Background Processing
You can use PHP-GTK in the background. Just call it with cron. Alternatively, you can set PHP to keep executing on the user exit. What was that function called? on_*_shutdown()? Could be dangerous though, what if it goes to loop-in your server? 30 mins is quite a few for a script to run. So, check also max_execution_time directiv in your PHP.INI. Or, the best is - loop up a way to reduce (or split) the times. Sincerely, Maxim Maletsky Founder, Chief Developer www.PHPBeginner.com // where PHP Begins -Original Message- From: Richard Perez [mailto:[EMAIL PROTECTED]] Sent: Wednesday, April 24, 2002 5:33 PM To: [EMAIL PROTECTED] Subject: [PHP] Background Processing Hi people!! I'm trying to find a way to handle this but I don't come up with anything. I need to execute a query to a DB using PHP. The thing is that the query takes 0.5 hours to execute and I can't wait that time with the browser opened in that page. What I want to do is to execute a PHP code block in some sort of background way so I can execute the query and send the results via email. Any ideas to do this?? Thanks a lot. Richard. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Background Processing
On Wed, 24 Apr 2002, Maxim Maletsky (PHPBeginner.com) wrote: You can use PHP-GTK in the background. Just call it with cron. Alternatively, you can set PHP to keep executing on the user exit. What was that function called? on_*_shutdown()? Could be dangerous though, what if it goes to loop-in your server? 30 mins is quite a few for a script to run. So, check also max_execution_time directiv in your PHP.INI. Or, the best is - loop up a way to reduce (or split) the times. Sometimes there isn't much choice. I recall an earlier project where we had an Oracle query that usually took about 12 hours to run. One approach that keeps fewer processes hanging around is to have the query store to a temporary table, and then just poll for a completed result set. miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Background processing / forking
Hi Natasha, Well the probably easiest shitty way to do it is: exec("theprogram 1 /some/file 21 "); would exec()ute theprogram and will put it's output in /some/file and stderr's output also in the /some/file, and at last signifies the backgroundness of the program. however as you mentioned C, the better way could fork it in C, and since i don't wanna get offtopic i won't mention it here. -:) HTH --- Natasha [EMAIL PROTECTED] wrote: hey, i wanted to know if there's a fork function in php, cause i don't see it in the manual. I basically wanna call a C program from PHP. Now the problem is that the C program will be running for longs periods like maybe half or even an hour. So i would basically want to just execute the program and return control to the script immediately so that the c program continues it's work. it's easy with forking. but i dont see it in php. thx. __ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] = To find out more about me : http://www.geocities.com/mimodit My bookmarks are available @ http://mukul.free.fr __ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Background processing / forking
Now the problem is that the C program will be running for longs periods like maybe half or even an hour. So i would basically want to just execute the program and return control to the script immediately so that the c program continues it's work. it's easy with forking. but i dont see it in php. It's quite easy with PHP as well, even though we do not have forking. Either use exec("nohup c-program") to detach the program, and return control back to the script, or execute it via a shutdown function. That way, the program gets executed after the script has finished. PEAR offers an abstraction for executing system commands. Look for CMD.php /A -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] background processing / forking
Disclaimer: The following post contains C code for *nix! Viewer discretion recommended! Hi, I'm back, I couldn't resist you mentioning C, so as you did, big fault, the code that follows is probably much better than exec, as an stderr terminal will still be attached, but anyway: exec("yourprogramname"); this /should/ work, if it don't then the before exec i mentioned would work! #include sys/types.h #include sys/time.h #include stdlib.h #include stdio.h #include string.h #include signal.h #include unistd.h void get_into_background(void) { pid_tpid; // all the familiar kitchenware! pid = fork(); if(pid != 0) exit(0); setsid(); // sets out process and group id as part of the session // but only if the process ain't a leader, hehe close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); // the program shouldn't acquire a terminal signal(SIGHUP, SIG_IGN); // incase we get HUP'd, ignore! pid = fork(); if(pid != 0) exit(0); chdir("/towhere"); umask(0); } void the_actual_exec(void) { charbuffer[1024]; char*args[3]; args[0] = "ls"; args[1] = "-F"; args[2] = 0; execv("/bin/ls", args); // 0 terminated array perror("execv"); // as exec dont return nutting // going past exec is an ERROR } int main(int argc, char **argv) { get_into_background(); the_actual_exec(); return 0; } = To find out more about me : http://www.geocities.com/mimodit My bookmarks are available @ http://mukul.free.fr __ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]