If I had a php file which was broken up by instances of javascript (specifically javascript sleep functions), how would that count towards the timeout the server has set? The script would look like: Some code in PHP A php end statement: ?> Some javascript (with a bunch of sleep functions) Some more PHP All within the same file. How would this affect the script timeout? Would it: Count both PHP instances together against the timeout? Count everything including the Javascript delay against the timeout? Count each PHP process as separate timeouts? And yea, I know that you can simply change the timeout setting on most servers, but some hosts lock that feature and I still want my script to work with them.
Any javascript outputted by php would not be ran until it is loaded in the browser. So the answer is, the javascript will not count towards the timeout of the server what so ever (besides the transfer time of the extra data).
It's kind of the opposite of that though. Now that I look at it, my example doesn't depict what I'm doing properly. It's more like the javascript is initiating php code every once in awhile (just as an example, to let javascript use a $_POST variable, among other things). So would each instance of PHP that the javascript initiates separately count towards the timeout? As an example: // THIS FILE IS CALLED INDEX.PHP <html> <head> <title>Hello</title> </head> <body> <!-- Some PHP code... --!> <? // Something that takes like 5+ seconds in PHP sleep(5); echo "I did something"; ?> <!-- Some Javascript code... --!> <script type="text/javascript"> // Do something with it that takes forever in javascript function sleep(milliseconds) { var start = new Date().getTime(); for (var i = 0; i < 1e7; i++) { if ((new Date().getTime() - start) > milliseconds){ break; } } } sleep(5000); document.write("I did something else..."); // Some other really long code in PHP (initiated by the javascript) <? sleep(5); echo "I lied, I really didnt do anything at all"; ?> </script> </body> </html> Code (markup): Would it count as 1 ten second timeout (both php scripts put together), 1 fifteen second timeout (the whole file including the javascript), or 2 five second timeouts (both php scripts counted separately, since the second one doesn't initiate until the javascript tells it to).
The javascript can't tell php to sleep unless it is making a request to the server, and even then the page itself would already be loaded and just waiting for a response. The javascript sleep(5000) call wouldn't run until the page is loaded in the browser, so it would take 10 seconds for the page to load. Then it would sit their 5 more seconds, then it would do nothing since print "something"; isn't javascript and is inside the script tags, print('something'); in javascript would phyisically print that text. The key is one language (PHP) is executed on the server before the page is sent to the browser, the other (Javascript) isn't executed until it is loaded in the browser and can't "interact" with PHP unless it is via another request (ajax), even then you would still need to handle the result (inserting the information into the DOM) with javascript.