php return loading message code example

Example: php return loading message

<?php
// Disable buffering
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('output_buffering', 'Off');
@ini_set('implicit_flush', 1);
// Flush buffers
ob_implicit_flush(1);
for ($i = 0, $level = ob_get_level(); $i < $level; $i++) ob_end_flush();
?><!DOCTYPE html>
<html>
<head>
  <title>Loading</title>
</head>
<body>
  <div id="loading">LOADING</div>
<?php
// We need to send enough junk messages to make it works for all browsers
echo str_repeat(" ", 1024), "\n";

ob_start();
// Long process starts here
// For this example, just sleep for 5 seconds
sleep(5); 
echo "Loaded";
// Flush output like this
ob_flush();
flush();
?>
</body>
</html>

Tags:

Misc Example