Jump to content

Delaying


turbocueca

Recommended Posts

use sleep:
[code]<?php

sleep(1);
echo "hello";

?>[/code]After one secound hello should appear. NOTE if you have a series of sleep functions ie:
[code]<?php

sleep(1);
echo "hello";

sleep(2);
echo "hello";

sleep(3);
echo "hello";

?>[/code]Nothing will be outputted for at least 6 secounds as the sleep functions add up to the total time php sleeps for. It will not show the first hello after 1 secound then the secound hello after two more secound and the last hello after three more secounds. it will show hellohellohello after 6 secounds has passed
Link to comment
https://forums.phpfreaks.com/topic/5195-delaying/#findComment-18441
Share on other sites

Here's a sample script to list data items at 1 second intervals

[code]<?php
     // php data - could be from database
  $item = array('Widget', 'Gizmo', 'Grommit', 'Wotsit');
?>
<HTML>
<HEAD>
<meta Name="generator" content="PHPEd Version 3.1.2 (Build 3165)">
<title>Sample delay script</title>
<meta Name="author" content="Barand">
<script LANGUAGE="javascript">

<?php
     // put php data into js array
  echo "var jsitems = new Array(";
  echo '"' . join('","', $item) . '");';
  echo "\n\n";
    //
  echo "var count = 0;\n\n";
?>

function displayItem() {
         var elem = document.getElementById("items");
         elem.innerHTML = elem.innerHTML + "<BR>" + jsitems[count];
         count++;
         if (count < jsitems.length) setTimeout("displayItem()", 1000);
}

</SCRIPT>
</HEAD>
<BODY onload='setTimeout("displayItem()", 1000);'>

Here are the items<br><br>
<DIV id='items' style="margin-left:50px; padding:10px; border: 1px solid silver; width: 200px; height:200px">
</DIV>

</BODY>
</HTML>[/code]

hope it helps
Link to comment
https://forums.phpfreaks.com/topic/5195-delaying/#findComment-18534
Share on other sites

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.