Setting up a Cron
Posted: Mon Jun 16, 2008 8:56 pm
I'm a little familiar with Cron and setting it up on PHP but for some unknown reason I simply cannot get the job to run. Here is my PHP code:
Pretty simple, if the cron file isn't there it creates it, otherwise it writes the given command and then calls crontab passing off the file path. Well according to the command given this job should call test.php every minute, and it's not. I've been debugging it for about 20 minutes now and have concluded the following:
1) I've called the "/usr/local/bin/php /home/joshg/public_html/test.php" command with PHP's exec() function and the script emailed me just like it should.
2) I went into CPanel and setup a nearly identical cron and it worked perfectly
3) I checked the cron file, the command looked fine
So basically I'm at a loss as to why it's not working. All I can assume is maybe it's something with the cron file being in my local directory? Any help would be appreciated. Thanks.
* EDIT *
I just called:
And noticed that the cron is not updating. It updates fine if I do it on CPanel but for some reason my PHP script is not updating it. Any idea?
Code: Select all
$command = "* * * * * /usr/local/bin/php /home/joshg/public_html/test.php";
$cron_file = "/home/joshg/public_html/cron/cronexec";
if (file_exists($cron_file)){
file_put_contents($cron_file, $command);
exec("crontab $cron_file");
} else {
touch($cron_file);
chmod($cron_file, 0777);
file_put_contents($cron_file, $command);
exec("crontab $cron_file");
}1) I've called the "/usr/local/bin/php /home/joshg/public_html/test.php" command with PHP's exec() function and the script emailed me just like it should.
2) I went into CPanel and setup a nearly identical cron and it worked perfectly
3) I checked the cron file, the command looked fine
So basically I'm at a loss as to why it's not working. All I can assume is maybe it's something with the cron file being in my local directory? Any help would be appreciated. Thanks.
* EDIT *
I just called:
Code: Select all
echo exec("crontab -l");