Search code examples
phpcroninstagramfile-get-contentsinstagram-api

why file_get_contents('external_url') is not working in cron job? Are there any alternate process?


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.


Solution

  • 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