You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

You can limit number of cron jobs, if you use PHP for DevOps software in CentOS 7, which can be easily implemented by checking process by shell_exec.

Below function enables you to check number of process that based on "PHP".

function count_process($process_name)
{
	// check process in the process list
	$bot_count_cmd = "ps aux | grep \"{$process_name}\" | wc -l";
	$bot_count=shell_exec($bot_count_cmd);
	$bot_count=intval( trim($bot_count) )/2; // you may need to tune the number based on your running environment

	return $bot_count;
}
// check cdn.php in the process list
$bot_count=process_count("php cdn.php");

// we will just keep max 5 cdn bots
if (($bot_count)<5) $m_cms->cdn_update( 60*20);
// check encoding.php in the process list
$bot_count=process_count("php encoding.php");

// we will just keep max 2 encoding bots
if (($bot_count)>2) exit;


  • No labels