gerkintrigg Posted September 29, 2013 Share Posted September 29, 2013 Fairly quick question about crons: I want to send a variable to my cron script (which works btw), so I can make sure it's authorised to run like this: Http://www.whatever.com/crons/my_script.php?auth_code=12345 Obviously that is the http address. Will it be different when I refer to the cron in the cron tab? Quote Link to comment https://forums.phpfreaks.com/topic/282543-cron-variables/ Share on other sites More sharing options...
trq Posted September 29, 2013 Share Posted September 29, 2013 Why would you want cron to execute a php script via http? You should put your php script somewhere outside of the web accessible directory and call it via php's cli. As for passing variables, if your going via http you have to use whatever mechanism http provides (such as that you have shown in your example). Quote Link to comment https://forums.phpfreaks.com/topic/282543-cron-variables/#findComment-1451781 Share on other sites More sharing options...
kicken Posted September 29, 2013 Share Posted September 29, 2013 Obviously that is the http address. Will it be different when I refer to the cron in the cron tab? That depends on how exactly you run the cron job. If you just use wget/curl/lynx to fetch the URL, then no it won't be any different. If you run the script using the CLI version of PHP then yes, you'll need to handle the variables differently. Quote Link to comment https://forums.phpfreaks.com/topic/282543-cron-variables/#findComment-1451785 Share on other sites More sharing options...
gerkintrigg Posted September 29, 2013 Author Share Posted September 29, 2013 Okay so if I move it out of the accessible public_html folder then I use cli to refer to the cron a use some kind of variable send mechanism to plonk a variable into the script? I guess I'll look that up. Thanks. FYI, the reason I'd use http is to run. Script that I DO want to access in the normal website life but do it as a scheduled event as well. It makes sense to only have one script doing one job. That's the whole point of database normalisation after all. ;-) Quote Link to comment https://forums.phpfreaks.com/topic/282543-cron-variables/#findComment-1451786 Share on other sites More sharing options...
RobertP Posted September 30, 2013 Share Posted September 30, 2013 well for example this is my crontab line.. * * * * * php /var/www/index.php cron-tick > /dev/null 2>&1cron-tick -- is my argument... http://php.net/manual/en/features.commandline.usage.php http://php.net/manual/en/reserved.variables.argv.php Quote Link to comment https://forums.phpfreaks.com/topic/282543-cron-variables/#findComment-1451789 Share on other sites More sharing options...
gerkintrigg Posted September 30, 2013 Author Share Posted September 30, 2013 Okay great. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/282543-cron-variables/#findComment-1451808 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.