gongpex Posted October 8, 2011 Share Posted October 8, 2011 Hello everyone, In javascript we can use "setTimeout()" to create timing function, but in php taqs I cannot found taqs same as "setTimeout()", I want to create PHP like this case: for 5 seconds it can display "please wait", but after 5 seconds (time over) it can display "HELLO" same as "setTimeout()" in javascript, But in PHP, what taq same as "setTimeout ? please tell me thank you Link to comment Share on other sites More sharing options...
JamesB Posted October 8, 2011 Share Posted October 8, 2011 php doesn't have any timer functions, remember the script runs from top to bottom and stops executing when it reaches the bottom.you can use sleep() and usleep() to "pause" the script, but try to avoid using these. http://www.php.net/manual/en/function.sleep.phphttp://www.php.net/manual/en/function.usleep.php Link to comment Share on other sites More sharing options...
gongpex Posted October 8, 2011 Author Share Posted October 8, 2011 If using "set_time_limit()? what's the difference? Link to comment Share on other sites More sharing options...
JamesB Posted October 8, 2011 Share Posted October 8, 2011 set_time_limit sets the maximum duration a script can run for, sleep/usleep will pause the script for a certain duration from where it is called from. Link to comment Share on other sites More sharing options...
boen_robot Posted October 8, 2011 Share Posted October 8, 2011 It's important to keep in mind the purposes of PHP and JavaScript.JavaScript runs on the client. As you use setTimeout(), other things run as well in parallel. User interaction events (clicks, key presses, mouse moves, etc.) are still detected and code is still executed if attached to these events, in turn allowing you to interact with the user without page reloads.PHP runs on the server. Before any interactions with the client start, PHP must give the client everything or at least everything that they need for the interaction. PHP is only triggered when the page is requested and can't be attached to interaction events.The mentioned sleep() function doesn't let you run things in parallel. It simply delays output (and inherently, user interactions) for the specified amount of time. The PHP script doesn't do anything for that time, and the client doesn't get to do anything while they wait.What is it exactly that you're trying to achieve anyway? Link to comment Share on other sites More sharing options...
gongpex Posted October 10, 2011 Author Share Posted October 10, 2011 Because I'm still worried to use javascript because, if user disable javascript intentionally, it can cause the website cannot runs well Link to comment Share on other sites More sharing options...
Synook Posted October 10, 2011 Share Posted October 10, 2011 PHP cannot replace JavaScript. You need to make your website work acceptably without it being able to display "HELLO" after waiting five seconds. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.