[PHP] Execute a php page and don't wait for it to finish
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-using-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
Re: [PHP] Execute a php page and don't wait for it to finish
On Tue, 2010-10-19 at 18:50 +0530, Ferdi wrote: 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-using-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 Ferdi: check out: http://us3.php.net/manual/en/function.ignore-user-abort.php I am looking to change a script/app that i have to use this (as the script takes a few seconds to finish, and there are people hitting the back button, or soemthign else that is screwing the submission. I haven't implemented it (life has been busy) yet, but it seems to be what I was looking for, which may be what you're looking for... Steve. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execute a php page and don't wait for it to finish
What about simply having the script trip a flag that another background script checks every 60 seconds or so? Once a minutes a background script checks to see if it needs to preform any tasks. When a user hits a certain page it does an ajax request to trip this flag and immediately returns. The next time the background script checks if it needs to do anything, it sees the tripped flag and preforms the relevant database copy - or whatever :-) Chris. On Tue, Oct 19, 2010 at 9:20 AM, Ferdi ferdinan...@printo.in wrote: 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-using-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
Re: [PHP] Execute a php page and don't wait for it to finish
A simple AJAX script would do the trick, no? Or does the script which was triggered by JS get aborted if that page is unloaded? If javascript is unavailable you could trigger it through the img tag like so: img width='0' height='0' src=updater.php alt= / Again, not sure if it will keep running if the caller is unloaded. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 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-using-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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Execute a php page and don't wait for it to finish
-Original Message- From: Sebastian Detert [mailto:php-maill...@elygor.de] Sent: Tuesday, October 19, 2010 6:51 AM To: Ferdi; PHP General Subject: Re: [PHP] 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