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

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

问题描述

我有一个脚本,它使用 file_get_contents() 从远程服务器获取 json 响应.虽然 file_get_contents() 在本地文件上正常工作但不能使用 http 或 https 它给我以下错误 file_get_contents(): http://wrapper is disabled in the server configuration by allow_url_fopenfile_get_contents(https://api.domain.com/resolve.json?url=blablabla) 中的 =0:无法打开流:找不到合适的包装器 ..是专用服务器,我有 WHM .. 我试过了

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. 在 WHM PHP 配置编辑器上设置 allow_url_fopen = on 但这不起作用.
  2. 在发生错误的目录中使用 allow_url_fopen = on 创建一个 php.ini 文件,但这不起作用.
  3. 在 PHP 脚本的开头添加了 ini_set('allow_url_fopen', 'On'); 但这不起作用.
  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 .

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

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

更新:

phpinfo();

给我

allow_url_fopen Off 
allow_url_include   Off 
always_populate_raw_post_data   Off

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

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

推荐答案

通过 ssh 登录到您的服务器并输入

Login to your server via ssh and type

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

在文件中,只需按"ctrl + w"并输入"allow_url_fopen"并返回,很可能你会先来解释,所以重复搜索一些时间.现在您可以从

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

allow_url_fopen=1

"ctrl + x"并用"y"确认文件保存.

然后输入

sudo service apache2 restart

这将重新启动 apache,以便可以加载新的 php.ini 配置.完成这些步骤后,您应该可以在外部使用 file_get_contents.

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.

旁注

如果找不到 php.ini 文件,您将在 phpinfo()

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天全站免登陆