PHP的file_get_contents返回null时于allow_url_fopen是 [英] php file_get_contents returns null when allow_url_fopen is on
本文介绍了PHP的file_get_contents返回null时于allow_url_fopen是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到的警告消息:的file_get_contents未能打开否认流的权限
I get the warning message: file_get_contents failed to open stream permission denied
我已经设置all_url_open就在php.ini文件中。
I have set all_url_open to on in the php.ini file.
我的PHP文件在我的Apache服务器,它正试图从一个Tomcat服务器访问同一个机器上的URL(即返回JSON)。
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.
在PHP文件code如下:
The code in the php file looks like:
$srcURL = 'http://samemachine:8080/returnjson/';
$results = file_get_contents($srcURL);
我自己也尝试卷曲,它没有返回值,不打Tomcat服务器之一:
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?
推荐答案
- 确保它确实
allow_url_fopen选项
,而不是all_url_open
为你写 - 仔细检查通过运行该
的phpinfo()
。请确保它列出的选项,因为启用。如果不重新启动你的web服务器 - 要调试卷曲问题,运行Wireshark的,看
罗
接口
- Make sure it's really
allow_url_fopen
and notall_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
这篇关于PHP的file_get_contents返回null时于allow_url_fopen是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文