php timeout function code example
Example 1: settimeout jquery
setTimeout(function(){ alert("Hello"); }, 3000);
Example 2: javascript settimeout
setTimeout(function(){
alert("Sup!");
}, 2000);
Example 3: php time a script
$time_start = microtime(true);
for($i=0; $i<1000; $i++){
}
$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
echo '<b>Total Execution Time:</b> '.($execution_time*1000).'Milliseconds';
Example 4: timeout php
<?php
set_time_limit(20);
while ($i<=10)
{
echo "i=$i ";
sleep(100);
$i++;
}
?>
Output:
i=0 i=1 i=2 i=3 i=4 i=5 i=6 i=7 i=8 i=9 i=10
Example 5: time function in php
Return the current time as a Unix timestamp, then format it to a date:
<?php
$timestamp = time();
echo $timestamp . "<br>";
echo date("d/m/Y", $timestamp);
?>