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

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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