Posts Tagged ‘activity indicator’

PHP Loading Time with Activity indication

Tuesday, November 18th, 2008

This is a simply way to show activity while loading, or pausing a site.

Example

This method will output a “.” every second for the designated time.  This method uses flush(); to output the current string while we’re inside the for loop.

This can be used to load files within the loop and out put a activity indicator, or pause the site and allow ads to be displayed for a few seconds before proceeding.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
// Default Message
echo "Loading.";
 
//Sleep for 20 seconds
$SleepTime = 20;
 
//Show activity while sleeping
for($i = 0; $i <= $SleepTime; $i++) 
{
   sleep(1);
   echo '.';
   flush();
} 
 
// Loading, sleeping, complete
echo "<br /><br />Loaded.";
?>
Rating: 0.0/10 (0 votes cast)