sleep - PHP: run php code every 10 seconds -
i want run php code every 10 seconds, code have problem
because functions random delay ( 2 seconds until 5 seconds )
i want exact run code on 10 seconds , passes function if time out or if more 5 seconds
code :
for($i=0;$i<=5;$i++){ echo date('y-m-d h:i:s').'<br />'; get_file_content('....'); //load file server ( make 2 seconds until 5 seconds ) sleep(10); // sleep 10 seconds }
result 1 :
2017-04-14 15:25:35 2017-04-14 15:25:46 2017-04-14 15:25:57 2017-04-14 15:26:08 2017-04-14 15:26:19 2017-04-14 15:26:30
another result :
2017-04-14 15:32:22 2017-04-14 15:32:34 2017-04-14 15:32:44 2017-04-14 15:33:01 2017-04-14 15:33:17 2017-04-14 15:33:29
i want result ( load file make long time )
exact result :
2017-04-14 15:25:00 2017-04-14 15:25:10 2017-04-14 15:25:20 2017-04-14 15:25:30 2017-04-14 15:25:40 2017-04-14 15:25:50
how in lines of :
for($i=0;$i<=5;$i++){ $previoustime = date(); echo date('y-m-d h:i:s').'<br />'; get_file_content('....'); //load file server ( make 2 seconds until 5 seconds ) sleep(10-(date()-$previoustime)); }
Comments
Post a Comment