bruno67 Posted February 3, 2007 Share Posted February 3, 2007 excuse me for bothering you, I'm quite new to php which I used only on hosted website not in my own machine. I would like to know how to create a php webpage which can complete a job even if the web page is closed from the users' browser. I need an application that, when called, performs a series of file copy from http locations to the server disc. I need that application to be completedeven if the page calling it is closed by the user. is that possible? In which way one can structure hosted webpages in order to make jobs on the server also if the calling page is closed before finishing the job? Thank you very much for your help, Bruno. Link to comment https://forums.phpfreaks.com/topic/36893-background-jobs/ Share on other sites More sharing options...
Orio Posted February 3, 2007 Share Posted February 3, 2007 There's a simple function for it, that you just need to call at the beginning of the script- ignore_user_abort(). On the beginning of you script call it, and the script will continue running even if the browser is closed. Orio. Link to comment https://forums.phpfreaks.com/topic/36893-background-jobs/#findComment-176001 Share on other sites More sharing options...
bruno67 Posted February 3, 2007 Author Share Posted February 3, 2007 Thank you so much Orio, there's still one thing unclear to me. let's take this example from php.net: <?php ignore_user_abort(); // run script in background set_time_limit(0); // run script forever $interval=60*15; // do every 15 minutes... do{ // add the script that has to be ran every 15 minutes here // ... sleep($interval); // wait 15 minutes }while(true); ?> since I use hosted website, how do you kill a job like that (it runs "forever") if you want? can you do it remotely (how?) or you have to contact the administrator to kill it? Link to comment https://forums.phpfreaks.com/topic/36893-background-jobs/#findComment-176187 Share on other sites More sharing options...
Orio Posted February 3, 2007 Share Posted February 3, 2007 I dont know if you can kill a script using shell, but you can be clever and do something like this- make a file/mysql-record that has the value of true (or 1) or false (or 0). On every loop the script will check if it's set true and if so it will stop. This way you can set it false whenever you want the script to stop. Here's an example using a file called "continue.txt" which holds the value 1 or 0 (for true or false). <?php ignore_user_abort(); // run script in background set_time_limit(0); // run script forever $interval=60*15; // do every 15 minutes... do{ // add the script that has to be ran every 15 minutes here // ... $continue = trim(file_get_contents("continue.txt")); sleep($interval); // wait 15 minutes }while($continue); ?> But if this is what you are looking for (do something every 15 minutes) you should look into crontabs. They are much easier to manage. When you use the ignore_user_abort() method for running a task every X time, you dont have any feedback- how can you know the script didn't encounter an error and stopped? It depends what exactly you want to do... That's my opinion anyway. Orio. Link to comment https://forums.phpfreaks.com/topic/36893-background-jobs/#findComment-176223 Share on other sites More sharing options...
bruno67 Posted February 3, 2007 Author Share Posted February 3, 2007 Thank you again very much Orio, nice idea to use a file to control operations. as per the crontab I really don't know what it is but if it's something on the server I have no access on it (i guess) because I'm talking about hosting service not my own machine. As per knowing if the job has stopped for some reason, I was thinking of writing to a log file. now I have to further think on the issue and clarify to myself how to build it. Thank you again very much for your help, Bruno. Link to comment https://forums.phpfreaks.com/topic/36893-background-jobs/#findComment-176284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.