cakephp - CLI cron job sending get request to URL but 404 for everyone else -
i setup cron job cakephp sends request url in cake application, (or runs function in controller). however, if user visits url, 404 prevent abuse.
how can accomplish this? this work well?
note: using cakephp 2.3.0
the easiest (and reasonably secure) way check user agent. (sample assumes you're using "wget" cron). in crontab, use have run @ 7 minutes after each hour:
7 * * * * cd /tmp; /usr/bin/wget http://domain/controller/cron; rm cron
if cron job running on same server website, can use "localhost" instead of "domain"; otherwise, use name of domain (ex: "www.example.com"). substitute name of controller want cron method in word "controller". next, in controller's php:
public function cron() { if (substr($_server['http_user_agent'], 0, 4) != 'wget') $this->redirect('/'); ...
it's "reasonably" secure, because it's not hard spoof user agent. can't give way generate 404 without knowing more app (someone else can, though); send them home page, maybe enough.
if want use different name (other "cron"), remember change crontab , php.
if you're not using cron call wget call method, can adapt whatever user agent string method use generates.
if me, i'd have check it's right time called cron (ex: within first 10 seconds of 7th minute of hour).
Comments
Post a Comment