Good morning everyone
plz i want to know how to create a cron job using php function and also how to stop this cron from working using php...
all that i need is to create a cron job using php and when the administrator press send -> the cron will be execute
and when he press stop -> the cron will be deleted from cpanel
note that: the administrator does not have an access to the cpanel and also if he has .. he can not deal with it.
so can anyone have a function to creeate a cron job using php? and also stop it?
// check for cron/Feed_cron file. If it doesn't exist create it.
// you must create the file from the browser to associate the proper group
if (file_exists($cron_file))
{ // if it exists, write new command
$open = fopen($cron_file, "w"); // This overwrites current line
fwrite($open, $command);
fclose($open);
// this will reinstate your Cron job
exec("crontab /home/egypthol/public_html/cron/Feed_cron") or die ("Error");
}
else
{ // if it Doesn't exist, Create it then write command
touch($cron_file); // create the file, Directory "cron" must be writeable
chmod($cron_file, 0777); // make new file writeable
// start the cron job!
exec("crontab /home/egypthol/public_html/cron/Feed_cron")
or die ("Error");
}
}
?>
this is my code... and it makes the file Feed_cron and make inside it the commad
but there is an error in the exec line coz when the page is loaded the die message ("error") appears.. so i found that the error is in the execute line
could u plz help me in solving this problem
If you use cPanel or similar for your web control panel, there should be an option for adding Cron Jobs there?
i want to make the cron job using code because the administrator can not use the cpanel or unnderstand how it works and also he dont have the right to enter to the cpanel and modify it.... so he want me to do the cron job using code without the need to know cpanel (i mean the administrator)