Created
July 31, 2014 06:55
-
-
Save vrushank-snippets/fd809625bcdb81358ab4 to your computer and use it in GitHub Desktop.
PHP: Dynamic Cron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(isset($_POST['matching_algo_run_time']) && !empty($_POST['matching_algo_run_time'])){ | |
$algo_time = explode(':', $_POST['matching_algo_run_time']); | |
$hours = $algo_time[0]; | |
$minutes = $algo_time[1]; | |
$hour_12 = ($hours > 12) ? ($hours + 12) - 24 : $hours + 12; | |
if($hour_12 == 24) | |
$hour_12 = '00'; | |
$output = shell_exec('crontab -l'); | |
$cron_file = '/tmp/crontab.txt'; | |
if(file_exists($cron_file)){ | |
unlink($cron_file); | |
echo exec('crontab -u www-data -r'); | |
} | |
$cron1 = "$minutes $hours * * * curl -s -m 10 http://localhost/one_degree/admin/welcome/send_email"; | |
$cron2 = "$minutes $hour_12 * * * curl -s -m 10 http://localhost/one_degree/admin/welcome/send_email"; | |
file_put_contents($cron_file, $output.$cron1.PHP_EOL.$cron2.PHP_EOL); | |
echo exec('crontab /tmp/crontab.txt'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment