How to run cronjobs per second?

On August 21, 2010, in CentOS, Fedora, Linux, Tricks, by phpsolutions

Have you checked my previous article on cronjobs…

http://blog.phpsolutions.co.in/tag/crontab-command-line/

To run cronjob per second you have to execute crontab/cronjob per minute and then have to run task in cron file per second using PHP function time_sleep_until().

<?php

$start = microtime(true);

for($ii=0;$ii<60;$ii++)
{

//……………………….

/// here is the tasks which need to run per second…

//……………………….

time_sleep_until($start + $ii + 1);
} // end for

if (!function_exists(‘time_sleep_until’))
{
function time_sleep_until($future)
{
if ($future < time())
{
trigger_error(“Time in past”, E_USER_WARNING);
return false;
}

usleep(($future – microtime(1))*1000000);
return true;
}
}

?>

Tagged with:  

One Response to How to run cronjobs per second?

  1. Anonymous says:

    I had been just browsing here and there along with to read this post. I have to admit that i’m from the hand of luck today if not getting this excellent post to see wouldn’t are already achievable for me, at least. Really appreciate your articles.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.