Jump to content

sleep() - how to use it for display purposes...


Tjorriemorrie

Recommended Posts

Hey, for simplicity: the user is at page1. from there it's redirected to page2. then page2 will redirect it to page1.

 

I have the redirection going fine, but the problem is that I want page1 to show "Loading...", then wait for 3seconds and then start loading page1.

 

So far I have: (note I'm only getting my toes wet, just trying to see how things work, thus redirect excl).

  <?php 
    $goto = $_SESSION['URLvisited'];
    if (!$CookieIsSet) {
  echo "Cookie could not be set";
  die();
  }
  	else {
  for ($i = 1; $i <= 10; $i++) {
    echo "Loading " . $i;
	sleep($i);
	}
  }

 

I'm just trying to get it to work with that for loop. But it doesn't show each 'loading'. Page2 stays blank and then throws the timeout error (which is fine).

 

How can I get echo's to show on the screen with sleep() inbetween?

 

Secondly, how is my script different from the example in the manual?? (coz mine isn't working  :P)

<?php

// current time
echo date('h:i:s') . "\n";

// sleep for 10 seconds
sleep(10);

// wake up !
echo date('h:i:s') . "\n";

?>

 

Link to comment
https://forums.phpfreaks.com/topic/98355-sleep-how-to-use-it-for-display-purposes/
Share on other sites

i'd use a meta refresh instead of trying to hack it together with PHP. send visitor to page 1 with meta refresh to the next page (even the same page), displaying "Loading..." or whatever.

Thanks BlueSkyIS. The other thing is that I want to put an if in. True will let it load and false won't let it load. So I was hoping this would've worked :( I guess I have to just ignore the sleep all together. Sigh, I hate it when I can't implement functions :(

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.