问题
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_fopenand notall_url_openas 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
lointerface
来源:https://stackoverflow.com/questions/10354805/php-file-get-contents-returns-null-when-allow-url-fopen-is-on