file_get_contents()不工作 [英] file_get_contents( ) not working

查看:342
本文介绍了file_get_contents()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本使用 file_get_contents()从远程服务器获取json响应。
while file_get_contents()在本地文件上正常工作,但不使用http或https它给我以下错误 file_get_contents http://在服务器配置中,通过 file_get_contents(https://api.domain.com/resolve.json?url=blablabla)中的allow_url_fopen = 0禁用wrapper :无法打开流:没有找到合适的包装器 ..它是一个专用的服务器,我有WHM ..我尝试了


  1. 在WHM PHP配置编辑器上设置 allow_url_fopen = on ,但这不起作用。

  2. 在发生错误的目录中,使用 allow_url_fopen = on 的php.ini文件。

  3. 添加了 ini_set('allow_url_fopen','On'); 到PHP脚本的开头,但是没有用。

我知道我可以使用Curl,但我想知道为什么这不工作..脚本在其他服务器和localhost上正常工作



更新:

  phpinfo 

给我

 code> allow_url_fopen Off 
allow_url_include Off
always_populate_raw_post_data Off

我的php.ini更改没有生效...我做错了什么?

解决方案

通过ssh登录到您的服务器和类型

  sudo nano /etc/php5/apache2/php.ini //<< ubuntu / debian服务器可能会因为文件中的

而有所不同,只需按 ctrl + w并键入allow_url_fopen并返回,很可能你会先解释一下,次。现在您可以从

更改条目

allow_url_fopen = 0





allow_url_fopen = 1



ctrl + x并使用y确认文件保存。



然后输入

  sudo service apache2 restart 
pre>

这将重新启动apache,以便加载新的php.ini配置。在这些步骤之后,您应该能够从外部使用 file_get_contents






SIDENOTE



如果您找不到您的php.ini文件,您将在<$

的顶部找到加载的php.ini文件的路径c $ c> phpinfo()




I have a script that uses file_get_contents() to get json response from remote server . while file_get_contents() is working properly on local files but not working with http or https it gives me the following error file_get_contents(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in and file_get_contents(https://api.domain.com/resolve.json?url=blablabla): failed to open stream: no suitable wrapper could be found .. it is a dedicated server and I have WHM .. I've tried

  1. setting allow_url_fopen = on on WHM PHP configuration Editor but This didn't work.
  2. creating a php.ini file with allow_url_fopen = on in the directory where the error occurred but this didn't work.
  3. added ini_set('allow_url_fopen', 'On'); to the start of the PHP script but this didn't work .

I know I can use Curl instead but I want to know why this is not working .. the script is working properly on other server and localhost

update :

phpinfo();

gives me

allow_url_fopen Off 
allow_url_include   Off 
always_populate_raw_post_data   Off

that means my php.ini changes didn't take effect .. what I'm doing wrong ?

解决方案

Login to your server via ssh and type

sudo nano /etc/php5/apache2/php.ini //<<<< ubuntu/debian server, might differ for you

in the file, simply press "ctrl + w" and type "allow_url_fopen" and Return, most probably you will come to the explanation first, so repeat the search a couple of times. Now you can change the entry from

allow_url_fopen=0

to

allow_url_fopen=1

press "ctrl + x" and confirm the file save with "y".

Then type

sudo service apache2 restart

This will restart apache so the new php.ini configuration can be loaded. After those steps, you should be able to use file_get_contents externally.


SIDENOTE

If you can't find your php.ini file, you will find the path to the loaded php.ini file in the top section of your phpinfo()

这篇关于file_get_contents()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆