isedeasy Posted August 10, 2010 Share Posted August 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/210268-running-a-php-script-via-cron/ Share on other sites More sharing options...
trq Posted August 10, 2010 Share Posted August 10, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/210268-running-a-php-script-via-cron/#findComment-1097262 Share on other sites More sharing options...
isedeasy Posted August 10, 2010 Author Share Posted August 10, 2010 It basically just promotes users, locks old threads and expires stuff. Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/210268-running-a-php-script-via-cron/#findComment-1097424 Share on other sites More sharing options...
trq Posted August 10, 2010 Share Posted August 10, 2010 It basically just promotes users, locks old threads and expires stuff. So, database stuff. No real need to use php. Quote Link to comment https://forums.phpfreaks.com/topic/210268-running-a-php-script-via-cron/#findComment-1097496 Share on other sites More sharing options...
isedeasy Posted August 10, 2010 Author Share Posted August 10, 2010 Well it also sends out emails and private messages via my php classes. Out of interest how would you go about this? Quote Link to comment https://forums.phpfreaks.com/topic/210268-running-a-php-script-via-cron/#findComment-1097514 Share on other sites More sharing options...
trq Posted August 10, 2010 Share Posted August 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/210268-running-a-php-script-via-cron/#findComment-1097515 Share on other sites More sharing options...
isedeasy Posted August 10, 2010 Author Share Posted August 10, 2010 Thanks for the help. I need to have a good read up on cron, this is the first time I have used a crontab file. Quote Link to comment https://forums.phpfreaks.com/topic/210268-running-a-php-script-via-cron/#findComment-1097518 Share on other sites More sharing options...
trq Posted August 10, 2010 Share Posted August 10, 2010 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" Quote Link to comment https://forums.phpfreaks.com/topic/210268-running-a-php-script-via-cron/#findComment-1097525 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.