Heyyy,
Does anyone know how i can get PHP to run a cron job that will execute a script on the first of every month?

Heyyy,
Does anyone know how i can get PHP to run a cron job that will execute a script on the first of every month?
Coming and going...
Highers are getting the better of me
create a file called crons.txt
put the WHOLE cron (including the * * * * * stuff, etc) you want to run it in
and in the same directory, create a php file that has the following contents in it:
then save + go to the file in you browser, then delete the filePHP Code:<?php exec("crontab /directory/to/crons.txt");?>![]()
Last edited by NN-Dom; 15-09-2008 at 03:23 PM.
so i could run that on installation?
And what code do i need to run a php file (in the crons.txt thing)
Coming and going...
Highers are getting the better of me
Also how would i go about editing existing crons that are set up?
Coming and going...
Highers are getting the better of me
Not all systems allow the use of crontab or exec() in general.
It depends on the user that Apache/cPanel is runinng on, and what permissions they have, if they have permission to edit the crontab from PHP/that user.
Is there a way of finding out if a site is allowed use of crontab ? Like i could do something where if their not allowed, the option to enable the cron services is disabled or something like that?
Coming and going...
Highers are getting the better of me
you *might* could do something like this, not sure if exec returns true/false though.
PHP Code:<?php
if(exec( "blabla" ) == false) {
exit( "ERROR! Could not access crontab. Please do this step manually." );
}
?>
Apparently not ;pOriginally Posted by php.net - exec() function
Return Values
The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.
To get the output of the executed command, be sure to set and use the output parameter.
hm it might just be easier to use a system LIKE pseudocron instead..
More control and cross-server compatability that way.
What you guys think?
Coming and going...
Highers are getting the better of me
Add the cron in cpanel cron manager.
IIRC you need:
php -f /path/to/script.php
Il just use a pseudocron like method ;p
And ryan - if i were to use crons it would have to be controlled by the script
Thanks anyways guys![]()
Coming and going...
Highers are getting the better of me
Want to hide these adverts? Register an account for free!