Jump to content

Running a PHP script via CRON


isedeasy

Recommended Posts

I am running some php via a cron and I was after the best way to achieve this. Currently I am doing it as follows:-

 

0 * * * * lynx -dump http://www.domain.com/script.php

 

This works fine but I don't want anybody being able to run the script by pointing their browser to the file.

 

Any advice on the best method? Cheers.

Link to comment
Share on other sites

Put the script outside of your servers document root and have php' cli execute it not the server.

 

0 * * * * /usr/bin/php /path/to/script.php

 

Most of the time (on this board) people use php for cron jobs when they don't even need to. What exactly does the script do?

Link to comment
Share on other sites

Database queries can be executed directly from your crontab file if there not too large, otherwise, yeah, I would write a script. Generally bash but yeah, php's fine if that's what you know.

 

I'm not knocking the use of php, (well not trying too) its just that I see allot of people writing scripts in php that could be easily written in one line within the crontab file itself.

Link to comment
Share on other sites

Its not that hard. The first 5 fields determine when the commands following will be executed.

 

For instance, if you want to give all your users 5 points every day they are a member. No need to write a script, it can be done with a single query and cron.

 

0 0 * * * mysql -uuname -ppword dbname -e "UPDATE users SET points=points+5"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.