+ 9

PHP sleep function causes Terminated Execution Timed Out! Why?

I tried to add a little delay into my code but it doesn't work. This code works perfectly on w3schools.com. Am I doing something wrong? https://code.sololearn.com/wJdfKVKhtpQZ/?ref=app

20th Feb 2021, 11:44 AM
Dual Core
Dual Core - avatar
4 Answers
+ 10
Josh Greig got it 👍 thanks again!
20th Feb 2021, 5:54 PM
Dual Core
Dual Core - avatar
+ 7
Thank you Josh Greig for your answer. Sounds like you have a point but then why setTimeout works perfectly in JS? There's a lot of web codes that have infinite loops and they run here without errors. Of course Sololearn freezes and you have to close the app. When the argument is less than 1 sleep ignored at all. I will email Sololearn if nobody knows what's wrong here. However people say that Sololearn staff is very busy and might not respond if the problem is not very serious. Lastly. I don't want to experiment with sleep. It's not very useful or important. After all my codes codes work fine without it. All wanted was to make my PHP codes work like my JS codes. Also it would be nice to split some large output into smaller print outs using some short time delays.
20th Feb 2021, 5:43 PM
Dual Core
Dual Core - avatar
+ 2
The Sololearn staff will know for sure but I'm confident they put an execution time limit on the script. Apparently, that limit is roughly 1 second. CPU processing time costs money and they need to cut an infinite loop short. 1 second appears to be where they draw the line. If you didn't sleep, you could do a lot of processing in 1 second so it is a pretty generous time limit. You can email info@sololearn.com your question if you want to hear from one of them. If you want to experiment lots with sleep, I suggest you install WAMP or XAMPP on your laptop or desktop and run scripts there. Running the script locally will let you learn more about how it executes and give you enough flexibility to make a complete website or web application. It also helps you access detailed logs that help you troubleshoot problems. If you run Windows, you can get WAMP from: https://www.wampserver.com/en/
20th Feb 2021, 5:09 PM
Josh Greig
Josh Greig - avatar
+ 1
Browser-based JavaScript runs in your web browser so it has no time limits. The "Web" code type is run completely in the web browser. Running code in your web browser doesn't cost Sololearn any money. If you run JavaScript with Sololearn's "NodeJS" code type, the following will time out like you experienced with PHP since NodeJS is executed in Sololearn's servers and not your web browser: function function1() { // stuff you want to happen right away console.log('Welcome to My Console,'); } function function2() { // all the stuff you want to happen after that pause console.log('Blah blah blah blah extra-blah'); } // call the first chunk of code right away function1(); // call the rest of the code and have it execute after 3 seconds setTimeout(function2, 3000);
20th Feb 2021, 5:50 PM
Josh Greig
Josh Greig - avatar