PHP 'file_get_contents' does not work from the server

I have website(PHP) hosted in a small business Yahoo and application(Java) hosted in Rackspace.

I do file_get_contentsfrom site to application. which works great in my local. but when I try to do the same after deploying it to the server, it will not work.

Here I make a request that sends a training list in format JSON.

PHP part

  $trainingArrayJson = file_get_contents('http://mywebapplication.com/publicTraining/getTrainingsAsJson/');
 $trainingArray =  json_decode($trainingArrayJson);
      -------
      -----

this does not work.

if i do

   $trainingArrayJson = file_get_contents('http://localhost:8080/publicTraining/getTrainingsAsJson/');
 $trainingArray =  json_decode($trainingArrayJson);

it works great.

+2
source share
3 answers

You need to allow

allow_url_fopen

in the php.ini configuration file. Some hosts prohibit this for security.

+3
source

URL- , fopen . . Fopen() , . . , , , .

+1

php.ini , :

; URL- (, http:// ftp://) . ; http://php.net/allow-url-fopen allow_url_fopen =

; / URL- (, http:// ftp://) . ; http://php.net/allow-url-include allow_url_include = .

0

Source: https://habr.com/ru/post/1661395/


All Articles