1

I created a php cron job, to fetch the Instagram feeds. My code is as follows..

$homepage = file_get_contents("https://api.instagram.com/v1/users/XXXXXX/media/recent?access_token=XXXXXXXXXX.XXXXXXX.XXXXXX&count=8", false, stream_context_create($arrContextOptions)); $json = json_decode($homepage);

When I execute this code through web-browser, it was working fine. But it was not executing from cron job.

I am using cron job command line as follows..

cd /home/MY_SITE/public_html/content/insta/ && php index.php > /dev/null 2>&1

please help me.. Thanks.

Thamilhan
  • 13,040
  • 5
  • 37
  • 59

1 Answers1

1

Also try to change your cron command to this

php /home/MY_SITE/public_html/content/insta/index.php > /tmp/log

and check /tmp/log file probably there is logged some error

Armen
  • 4,064
  • 2
  • 23
  • 40
  • Thanks @Armen, will try this and let you know. – webskripti.satya Dec 04 '15 at 07:28
  • hmm that /tmp/ folder is writable for www-data and after first execution php should be able to create it , but yes you can try to create it manually and chmod /tmp/log to 0777, and set cron to be executed every 1 min by adding */1 * * * * and after one minute check /tmp/log file – Armen Dec 04 '15 at 07:37
  • I am getting the below code in log file. `Status: 404 Not Found X-Powered-By: PHP/5.4.43 Content-type: text/html No input file specified.` – webskripti.satya Dec 04 '15 at 07:52
  • Seems your instagram link is wrong, but you can try first one again run your index.php with browser with enabled php errors `ini_set('display_errors', 1)` and check if that error exists on page or check /var/log/apache2/error.log file for same error and if it present then you have to convert your `file_get_contents` to `curl` request it works more stable as suggested for example here - http://stackoverflow.com/questions/8204586/file-get-contents-and-error-codes – Armen Dec 04 '15 at 08:18
  • No @armen, the given link is correct, It is working fine from web-browser.. I also tried curl.. but no luck.. Thanks. – webskripti.satya Dec 04 '15 at 10:00