Jump to content

Script works if run from Browser - Error from Cron


over9k

Recommended Posts

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

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"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.