Handling Extended Script Execution Times

liunx

Guest
A couple of questions:<br /><br />(1) I have some PHP code that may take a while to execute - say 30-45 seconds or more - and I'm concerned that a browser may give up, and report an error because a page is not returned within a certain amount of time. How can I handle this?<br /><br />Should my PHP script (that generates the webpage) call another PHP script to do the long-processing task, allowing it to exit earlier (with a generated webpage), or what?<br /><br />(2) ( a ) I'm interested to know how some of these travel sites (Orbitz, Priceline etc.) can go off and do a search, that sometimes goes on for a while. <br /><br />( b ) And sometimes I've noticed these types of pages will refresh, saying things like "Hang on in there... we're still searching."<br /><br />Does anybody have any advice regarding these questions, or pointers to more information?<br /><br />Thanks in advance, Simon.<!--content-->
I never did something like that but my first guess would be just what you said, use one script to do the processing while another script presents a page to the user, saying the search is being performed.<br /><br />I don't know how other sites do it but I'm sure you can find some good tutorials about it if you search for something like "php search engine tutorial" on Google.<br /><br />Here's one: <a href="http://www.devarticles.com/c/a/MySQL/Developing-A-Site-Search-Engine-With-PHP-And-MySQL/1/" target="_blank">http://www.devarticles.com/c/a/MySQL/Devel...HP-And-MySQL/1/</a><br /><br />Hope this helps <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><br /><br />PS - Do keep in mind that if you're on a shared server and your script takes up excessive resources, your account may get suspended in order to protect the integrity of the server and the other clients' accounts.<!--content-->
Thanks for the reply.<br /><br />(1) What are the indicators of my script taking up "excessive resources" and how can I measure this? (And how do you?) Is it measured by execution time and/or CPU processing? (because some operations can be more CPU intensive, such as heavy math.)<br /><br />(2) If just by execution time, is it like "your script cannot consume a timeslice of more than 10%" i.e. for every minute the server is running everybody's scripts, my script can only be executing for 6 seconds of that minute. If it hangs around for longer it's in trouble...<br /><br />(3) How can my script detect WITHIN ITSELF if it is using up "excessive resources". Are there any functions I can call, and/or flags I can read?<br /><br />(4) What do you mean by "getting suspended." Do I get any sort of warning, automated or from a human?<br /><br />(5) If my script does start to use excessive resources, can't the server jump in immediately and ( a ) pause my processing or ( b ) just stop the script without resuming? Kind of like a parent observing a child taking a drink, and the child not coming up for air, so the parent steps in saying "OK, that's enough for you at the moment."<!--content-->
1 - If I'm not mistaken, the server load is calculated from various factors, such as CPU load, hard disk I/O (input/output), memory I/O... I'm not sure but I believe it's something like this. Execution time is not a good factor for measuring the load a script causes on the server, because a script can get halted waiting for something from another server, for instance, but during that time it is not causing any load to the server it is running on. You have a server load indicator on your cpanel (inside the "server status" page. link on the menu on the left) and you can make some experiments using that server load indicator to get an idea of whether your script is causing a big load on the server.<br /><br />2 - As I said above, I don't think it's measured by execution time <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><br /><br />3 - Now that's a very good question but I really don't know the answer. A Google search for "PHP server load" gave me some results but I don't have the time to investigate right now. But I'll be back to it, because it's something that I'd like to learn how to do.<br /><br />4 - Well, if one of the techs notices something unusual on a server (or if a customer complains that the server is slow and the issue is investigated) and he/she comes to the conclusion that it is a script in your account that is causing the high loads, you will be asked to see what's wrong with the script or, if it's nothing wrong and the script does cause the server loads to go high, you'll be asked to remove it. I think your account would only be suspended if it is causing really high loads on the server, like bringing the server to a crawl and preventing the rest of the customers from having their sites working fast. Of course you will get a warning in both cases. The difference is that if the script is drowning the server, it's a more urgent matter and your account may be immediately suspended to avoid the other customers from being affected. Someone will then contact you to solve the problem.<br /><br />5 - I don't believe this is possible here on TCH. Actually, I don't think I have ever seen this at any budget hosting company. Such monitoring systems are complex and I have only seen them in BIG hosting companies.<br /><br /><br />Hope this helps <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
 
Top