php file_get_contents returns null when allow_url_fopen is on

喜夏-厌秋 提交于 2019-12-19 08:04:41

问题


I get the warning message: file_get_contents failed to open stream permission denied

I have set all_url_open to on in the php.ini file.

My php file is in my apache server and it is trying to access a url (that returns JSON) from a tomcat server on the same machine.

The code in the php file looks like:

  $srcURL = 'http://samemachine:8080/returnjson/';

  $results = file_get_contents($srcURL);

I have also tried curl and it returns nothing and doesn't hit the tomcat server either:

    function curl($url){
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Language: en-us'));
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        $data = curl_exec($ch);

        curl_close($ch);
        return $data;
    }

Why is permission denied?


回答1:


  • Make sure it's really allow_url_fopen and not all_url_open as you wrote
  • Double-check this by running phpinfo(). Make sure it lists the option as enabled. If it doesn't restart your web server
  • To debug your curl problem, run Wireshark and watch on the lo interface


来源:https://stackoverflow.com/questions/10354805/php-file-get-contents-returns-null-when-allow-url-fopen-is-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!