Jump to content

Archived

This topic is now archived and is closed to further replies.

smith.james0

Cron jobs

Recommended Posts

I want to create a php cron job. I but i don't know much about them, do you just write it as a normal php file?

Thanks James

Share this post


Link to post
Share on other sites
yes. you write your php script the way you would do any php script. have it do whatever you want it to do. Some people throw in some security on the script, like checking to see if the IP address trying to access the page is only the server's IP address, and you can also change the CHMOD on it for read only by server. stuff like that. I guess it depends on what the script is for, as to how secure you want it.

then you go to cpanel and setup the cron job for how often you want your script to be run. or you can do it on command line through shell.

Share this post


Link to post
Share on other sites
I am trying to get to work the People on line script from this site. The last page has this

<?
// Database connection information here

$maxtime = time() -600;
$sql = mysql_query("DELETE FROM ppl_online WHERE UNIX_TIMESTAMP(activity) < '$maxtime'");
$rows = mysql_affected_rows();

echo "Total of $rows Deleted";
?>


It work ok if you call the page but when it's done via cron, I get this email.

/home/*********/public_html/cron/delete_ppl_online.php: line 1: ?: No such file or directory
/home/*********/public_html/cron/delete_ppl_online.php: line 2: //: is a directory
/home/*********/public_html/cron/delete_ppl_online.php: line 4: syntax error near unexpected token `"localhost",'
/home/*********/public_html/cron/delete_ppl_online.php: line 4: ` $db=mysql_connect ("*********", "*********", "*********") or die ('I cannot connect to the database because: ' . mysql_error());'

Any ideas, Thanks James

Share this post


Link to post
Share on other sites
if the script works fine when you call it in your browser, then it is not a connection issue.

the error is fairly straightforward. it's telling you that the directory you put in your command does not exist. make sure in your cron job command it points to the proper directory that your script is in (no typos in the folder names, pointing to the right folder, etc....)

Share this post


Link to post
Share on other sites
I have this is the cron control panel

/home/********/public_html/cron/delete_ppl_online.php>/dev/null


Is this right?

Do you have to chmod it?

Many thanks James

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.