天空小小岛技术论坛

 找回密码
 注册
搜索
查看: 28360|回复: 0
打印 上一主题 下一主题

[配置] file_get_contents(): Unable to find the wrapper "https"解决方案

[复制链接]
跳转到指定楼层
1#
一粒米 发表于 2013-12-9 21:36:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
问题表现
file_get_contents 读取一个正常的 https 的url时,返回 false

打开报错
错误提示
  1. PHP Warning:  file_get_contents(https://graph.qq.com/): failed to open stream: No such file or directory in Command line code on line 1
复制代码


原因
php 所在的环境没有打开 openssl 的支持

解决方法
一、在 windows 下
只要打开相应的 dll 即可,就是找到 php.ini

  1. ;extension=php_openssl.dll
复制代码

前的分号去掉,重启 web 服务。
二、在 linux 下
重新编译 php,加入
  1. '--with-openssl'
复制代码
参数
或者单独编译 openssl,然后在 php.ini 里添加
  1. extension = openssl.so
复制代码
加载该模块

========
如果没有条件修改环境,并且服务器支持 curl,可以使用以下函数替换 file_get_contents
  1. function _file_get_contents($url) {

  2.         if (!function_exists('curl_init')) {  
  3.                 return false;
  4.         }

  5.         $timeout = 10;
  6.         $ch = curl_init();
  7.         curl_setopt($ch, CURLOPT_URL, $url);
  8.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  9.         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  10.         $contents = curl_exec($ch);
  11.         curl_close($ch);

  12.         return $contents;
  13. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|天空小小岛  |京ICP备2025130156号|

GMT+8, 2025-6-21 18:17 , Processed in 0.092314 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表