Dynamic sleep for infinite loops based on cpu

May 11, 2017

Based on this function http://ivangospodinow.com/php-how-to-calculate-system-processors-load-in-percent/

we are getting current cpu load.

usleep(1000000 * systemLoadInPercent() / 100);

Result: 54.3% cpu load, sleep 0.543 sec

 

tags:
posted in php by Ivan Gospodinow

Follow comments via the RSS Feed | Leave a comment | Trackback URL

Leave Your Comment

 
 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org