robgood Posted September 9, 2007 Share Posted September 9, 2007 hi, I am looking to delay a script from running for about 8 seconds and display an animated gift load image while the delay is running. This is just for a bit of fun really to give the illusion that something is processing in the background . Is there any way in php to do this? Quote Link to comment https://forums.phpfreaks.com/topic/68587-solved-delaying-a-script-from-running-and-having-a-animated-load-gif/ Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2007 Share Posted September 9, 2007 sleep(; That will delay the code. But why not just use a META refresh set to 8 seconds and then send the user to the PHP page without a delay? Quote Link to comment https://forums.phpfreaks.com/topic/68587-solved-delaying-a-script-from-running-and-having-a-animated-load-gif/#findComment-344780 Share on other sites More sharing options...
LiamProductions Posted September 9, 2007 Share Posted September 9, 2007 Try: http://www.php.net/sleep <?php echo "Script here"; sleep(; echo "Img here"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/68587-solved-delaying-a-script-from-running-and-having-a-animated-load-gif/#findComment-344781 Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2007 Share Posted September 9, 2007 That will show the image AFTER the sleep() but not during it as required. You could put the image before the sleep() but then you are stuck with the image on the page unless you META refresh to another page. Quote Link to comment https://forums.phpfreaks.com/topic/68587-solved-delaying-a-script-from-running-and-having-a-animated-load-gif/#findComment-344783 Share on other sites More sharing options...
GingerRobot Posted September 9, 2007 Share Posted September 9, 2007 Liam, that code would simply spend a fraction over 8 seconds loading, then display the text 'script here img here'. You can have output sent to the browser whilst the script is processing, if you use the flush function. For example: <?php for($x=1;$x<=5;$x++){ echo $x.'<br />'; flush(); sleep(1); } ?> With regards to the question, i agree with BlueSky. A delayed meta refresh would be better. Although, if you wanted to give the appearance of no reload, to enhance the 'illusion' of some loading time, then an AJAX approach would work more smoothly. Quote Link to comment https://forums.phpfreaks.com/topic/68587-solved-delaying-a-script-from-running-and-having-a-animated-load-gif/#findComment-344786 Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2007 Share Posted September 9, 2007 ah yes, I always forget Ajax even though I use it sometimes. Good idea. Quote Link to comment https://forums.phpfreaks.com/topic/68587-solved-delaying-a-script-from-running-and-having-a-animated-load-gif/#findComment-344787 Share on other sites More sharing options...
robgood Posted September 9, 2007 Author Share Posted September 9, 2007 thanks, i have no clues about ajax so i am going to go with the meta refresh to another page option, as it's a multi purpose page, so presumably it would delay the page loading for each action, rather than just the last step. It's a series of forms. Quote Link to comment https://forums.phpfreaks.com/topic/68587-solved-delaying-a-script-from-running-and-having-a-animated-load-gif/#findComment-344789 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.