Terminate PHP Loop After a Certain Time

We all know every loop has a termination condition (conditions can be anything). And this code snippet is for terminating a while loop after a certain time. This is an actually funny script which is, increasing a value a certain time and then decreasing that value a certain time period.

From the above code snippet, you can see there is variable called $totalTime which carrying the total number of execution time (in second) for loop. Then $totalTime is divided into the two periods, and the first half is using to increasing the $counter value and the second half is using to decreasing that $counter value.

Output:

Terminating a PHP loop after a certain time preiod Raw

 

Published by

Sohel Rana

PHP Programmer, Software Engineer & Technology lover

Leave a Reply

Your email address will not be published. Required fields are marked *