over9k Posted December 30, 2009 Share Posted December 30, 2009 The Line in Question is: <?php $weatherApi = implode('', file('http://www.google.com/ig/api?weather=65459')); ... Cron is returning: /home/me/public_html/extra/weatherGet.php: line 1: ?php: No such file or directory /home/me/public_html/extra/weatherGet.php: line 2: syntax error near unexpected token `(' /home/me/public_html/extra/weatherGet.php: line 2: ` $weatherApi = implode('', file('http://www.google.com/ig/api?weather=46802'));' I have a lot of code that relies on the contents of $weatherApi to be the output of: http://www.google.com/ig/api?weather=65459 It works fine if I run the script by entering the URL into the browser but fails when scheduled by Cron. Any help is greatly appreciated, thanks Quote Link to comment https://forums.phpfreaks.com/topic/186700-script-works-if-run-from-browser-error-from-cron/ Share on other sites More sharing options...
premiso Posted December 30, 2009 Share Posted December 30, 2009 Post the CRON line you have. As that code above looks fine, chances are your PHP CLI syntax is incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/186700-script-works-if-run-from-browser-error-from-cron/#findComment-985982 Share on other sites More sharing options...
over9k Posted December 30, 2009 Author Share Posted December 30, 2009 */5 * * * * /home/me/public_html/extra/weatherGet.php Thanks Premiso I plan on making it run less frequently when I get it working, Running it every 5 min for now. Permissions on weatherGet.php are 775 Quote Link to comment https://forums.phpfreaks.com/topic/186700-script-works-if-run-from-browser-error-from-cron/#findComment-985993 Share on other sites More sharing options...
premiso Posted December 30, 2009 Share Posted December 30, 2009 Your cron is setup to execute just the page, it is going to read it in and attempt to execute it as a shell commands. You either have to send it to the PHP CLI: http://www.devarticles.com/c/a/PHP/PHP-CLI-and-Cron/1/ Or open a browser instance to that page. I would suggest the CLI method from the link I posted above. EDIT: Modified the URL to the correct "Part" Quote Link to comment https://forums.phpfreaks.com/topic/186700-script-works-if-run-from-browser-error-from-cron/#findComment-985996 Share on other sites More sharing options...
over9k Posted December 30, 2009 Author Share Posted December 30, 2009 Thanks Premiso Working Cron line: */5 * * * * php /home/me/public_html/extra/weatherGet.php Quote Link to comment https://forums.phpfreaks.com/topic/186700-script-works-if-run-from-browser-error-from-cron/#findComment-985999 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.