views:

109

answers:

4

I have a php file which uses file_get_contents()

It works fine in the browser, but fails with the following error when run as a cron job:

Warning: file_get_contents(): URL file-access is disabled in the server configuration in /path/to/the/phpfile.php on line 22

This is what I'm using:

/usr/bin/php5 -q /path/to/the/phpfile.php

Iv'e already set allow_url_fopen = true in php.ini but this doesn't seem to have any effect.

Everything works perfectly in the browser though. How can this be fixed?

A: 

You might unintentionally have more than one copy of PHP and/or php.ini on the system. Do you have admin rights on the PC? Do a global search for php and see what turns up.

zildjohn01
This is WRT my web server and I don't have access to the PC. by "copy of PHP" do you mean different versions of PHP?
Yeti
I meant either different installations, different versions, or different config files. For example, chronos's answer.
zildjohn01
+2  A: 
  1. Do php --info | more
  2. run and see which php.ini it uses (top 5 lines)
  3. change that php.ini file

Or you can use the --php-ini /path/to/ini (do man php) to specify the ini file you want to use.

Itay Moav
I feel that merging my answer into yours would make for a fairly complete answer :)
chronos
php --info " more showed - /usr/local/php-5.2.6-1/etc/php.ini. But I cannot locate that folder?
Yeti
I have access to /home/my_site_folder but I don't see /usr anywhere. Does this mean I wont be able to change the php.ini file?
Yeti
+1  A: 

At least some Linux distributions have multiple PHP configurations (php.ini files). For example, Debian testing has these two:

/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini

In the example above different PHP configurations are used for web invocation (via apache) and for command-line invocation.

This might be your problem.

chronos
+1  A: 

If you are loading a file from a remote system, you should be using curl instead. file_get_contents doesn't handle network delays, redirects or error capture. And is obviously disable in the server configuration.

Brent Baisley