php 无法找到带有 file_get_contents 的包装器“https”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18643572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to find the wrapper "https" with file_get_contents
提问by John Smith
Calling file_get_contents() with https:// urls give me the following error:
使用 https:// url 调用 file_get_contents() 会给我以下错误:
warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?
I've read 10+ SO questions and all of them say to enable extension=php_openssl.dll
我已经阅读了 10 多个 SO 问题,所有这些问题都说要启用 extension=php_openssl.dll
I did this and I'm still having issues...
我这样做了,但我仍然遇到问题......
What else could it be?
还能是什么?
回答by Amit Shah
SOLVED
解决了
To solve this error, you need to install the OpenSSL
package for PHP on your webserver.
要解决此错误,您需要OpenSSL
在您的网络服务器上安装PHP 软件包。
On a FreeBSDserver, you may need to install the following package: php53_openssl
and restart your webserver.
在FreeBSD服务器上,您可能需要安装以下软件包:php53_openssl
并重新启动您的网络服务器。
On a Windowsserver, open your php.ini
config file and simply uncomment the following line:
在Windows服务器上,打开您的php.ini
配置文件并简单地取消注释以下行:
;extension=php_openssl
and restart the webserver. The error should be resolved.
并重新启动网络服务器。应该解决该错误。
Reference: I leart it from this linkwhich worked for me.., so credit goes to him.
回答by Артем
For PHP 7 on Windows 64bit be sure to put libcrypto-1_1-x64.dll
to the environmental variable path. For example: C:\php\libcrypto-1_1-x64.dll;
对于 64 位 Windows 上的 PHP 7,请务必放入libcrypto-1_1-x64.dll
环境变量路径。例如:C:\php\libcrypto-1_1-x64.dll;
回答by Vincent
I just wanted to add this tidbit because I struggled for hours with this issue and finally figured out something that works. With a lot of these WAMP/XAMP/MAMP installations, the configuration files are placed in non-standard directories (i.e., C:\MAMP\conf\php\php7.2.10\php.ini). You need to make sure that your php cli has loaded the INI you are modifying.
我只是想添加这个花絮,因为我在这个问题上挣扎了几个小时,终于找到了一些有效的方法。很多这样的 WAMP/XAMP/MAMP 安装,配置文件都放在非标准目录中(即 C:\MAMP\conf\php\php7.2.10\php.ini)。您需要确保您的 php cli 已加载您正在修改的 INI。
$ php --ini
If it is not pointing to the correct INI, or loads no configuration file at all, you can change the PHPRC environment variable for the user executing the script to point to the correct location for the INI that you have correctly modified. Also, ensure that the extension_dir parameter in php.ini is contains the correct path to where your extensions are stored.
如果它没有指向正确的 INI,或者根本没有加载配置文件,您可以更改执行脚本的用户的 PHPRC 环境变量,以指向您正确修改的 INI 的正确位置。此外,请确保 php.ini 中的 extension_dir 参数包含存储扩展的正确路径。
Hope this helps.
希望这可以帮助。
回答by Anuga
Like people say, check with the configuration.
就像人们说的,检查配置。
phpinfo.php
phpinfo.php
<?php
phpinfo();
?>
Search for OpenSSL on the webpage. Also, don't forget to restart the WebServer after altering the php.ini file.
在网页上搜索 OpenSSL。另外,不要忘记在更改 php.ini 文件后重新启动 WebServer。
If you can't use file_get_contents(), use cURL instead if available, it's better in many ways and faster.
如果您不能使用file_get_contents(),请改用 cURL(如果可用),它在很多方面都更好,而且速度更快。
function url($url,$option = null) {
$cURL = curl_init();
if ($option) {
curl_setopt($cURL, CURLOPT_URL, $url.$option);
} else {
curl_setopt($cURL, CURLOPT_URL, $url);
}
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL, CURLOPT_AUTOREFERER, 1);
curl_setopt($cURL, CURLOPT_HTTPGET, 1);
curl_setopt($cURL, CURLOPT_VERBOSE, 0);
curl_setopt($cURL, CURLOPT_HEADER, 0);
curl_setopt($cURL, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($cURL, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($cURL, CURLOPT_DNS_USE_GLOBAL_CACHE, 0);
curl_setopt($cURL, CURLOPT_DNS_CACHE_TIMEOUT, 2);
$output['page'] = curl_exec($cURL);
$output['contentType'] = curl_getinfo($cURL, CURLINFO_CONTENT_TYPE);
curl_close($cURL);
return $output;
}
$page = url('https://example.com/','i/like/subfolders');
回答by coderama
I had the same problem. I was trying to access facebook graph. It wasn't that it could not access the URL, it was that Facebook was returning a 400 error because I wasn't passing parameters through. Try connecting to HTTPS on a site that will have a working HTTPS connection. E.g. Try this:
我有同样的问题。我试图访问 Facebook 图。并不是它无法访问 URL,而是 Facebook 返回了 400 错误,因为我没有传递参数。尝试在具有可用 HTTPS 连接的站点上连接到 HTTPS。例如试试这个:
file_get_contents("https://www.namhost.com");
If that works, you must see why the HTTPs connection you are connecting to is failing, because the problem isn't that you can't connect to HTTPs, but rather that what you are connecting to isn't liking the request.
如果可行,您必须了解您连接到的 HTTPS 连接失败的原因,因为问题不在于您无法连接到 HTTPs,而是您连接的对象不喜欢该请求。
回答by Kanishk Dudeja
Please ensure if allow_url_include and allow_url_fopen are set to 'On' in php.ini.
请确保在php.ini 中allow_url_include 和allow_url_fopen 是否设置为“On”。
Uncomment them if these lines are commented.
如果这些行被注释,则取消注释它们。
Also, you can use the following script for diagnostics: (taken from the accepted answer on How to get file_get_contents() to work with HTTPS?)
此外,您可以使用以下脚本进行诊断:(取自关于如何让 file_get_contents() 与 HTTPS 一起工作?)
$w = stream_get_wrappers();
echo 'openssl: ', extension_loaded ('openssl') ? 'yes':'no', "\n";
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
echo 'wrappers: ', var_dump($w);