php timeout function code example

Example 1: settimeout jquery

setTimeout(function(){ alert("Hello"); }, 3000);

Example 2: javascript settimeout

setTimeout(function(){
 	alert("Sup!"); 
}, 2000);//wait 2 seconds

Example 3: php time a script

//place this before any script you want to calculate time
$time_start = microtime(true); 

//sample script
for($i=0; $i<1000; $i++){
 //do anything
}

$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 
/* Unix Timestamp */
$timestamp = time();
echo $timestamp . "<br>";
echo date("d/m/Y", $timestamp);
?>

Tags: