php 如何启用 HTTPS 流包装器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2305954/
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
How to enable HTTPS stream wrappers
提问by Tamppox
I installed php5 on my windows system and tried to execute the following script with a command-line console:
我在 Windows 系统上安装了 php5,并尝试使用命令行控制台执行以下脚本:
<?php
// load in credentials
$creds = parse_ini_file('/etc/aws.conf');
// Define query string keys/values
$params = array(
'Action' => 'DescribeAvailabilityZones',
'AWSAccessKeyId' => $creds['access_key'],
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
'Version' => '2008-05-05',
'ZoneName.0' => 'us-east-1a',
'ZoneName.1' => 'us-east-1b',
'ZoneName.2' => 'us-east-1c',
'SignatureVersion' => 2,
'SignatureMethod' => 'HmacSHA256'
);
// See docs
// http://tr.im/jbjd
uksort($params, 'strnatcmp');
$qstr = '';
foreach ($params as $key => $val) {
$qstr .= "&{$key}=".rawurlencode($val);
}
$qstr = substr($qstr, 1);
// Signature Version 2
$str = "GET\n"
. "ec2.amazonaws.com\n"
. "/\n"
. $qstr;
// Generate base64-encoded RFC 2104-compliant HMAC-SHA256
// signature with Secret Key using PHP 5's native
// hash_hmac function.
$params['Signature'] = base64_encode(
hash_hmac('sha256', $str, $creds['secret_key'], true)
);
// simple GET request to EC2 Query API with regular URL
// encoded query string
$req = 'https://ec2.amazonaws.com/?' . http_build_query(
$params
);
$result = file_get_contents($req);
// do something with the XML response
echo $result;
But it says that it's unable to find the wrapper "https" and asks if I forget to enable it when I configured PHP.
但是它说它找不到包装器“https”,并询问我在配置 PHP 时是否忘记启用它。
What is the problem and how to settle it?
问题是什么以及如何解决?
回答by Drew
1: Check which wrappers are installed.
1:检查安装了哪些包装器。
<?php var_dump(stream_get_wrappers()); ?>
2: If you dont see "https" on the list, add to/uncomment from php.ini
2:如果在列表中没有看到“https”,请在php.ini中添加/取消注释
extension=php_openssl.dll
Restart your server*, and your done.
重启你的服务器*,大功告成。
*if server fails to restart go download php_openssl.dll from someplace and stick it in your extensions directory defined in the php.ini file, restart server, say a few hell mary's and pray.
*如果服务器无法重新启动,请从某个地方下载 php_openssl.dll 并将其粘贴到 php.ini 文件中定义的扩展目录中,重新启动服务器,说几句地狱玛丽并祈祷。
回答by Pascal MARTIN
The file_get_contentsline, at the end of your script, is trying to send an HTTPS request -- see the URL in $req, which starts by 'https://ec2...'.
file_get_contents脚本末尾的这一行正在尝试发送 HTTPS 请求 - 请参阅 中的 URL $req,该URL 以开头'https://ec2...'。
For this to be possible, PHP needs a "wrapper" to send HTTPS requests -- which doesn't seem to be installed on your system ; which means you cannot send HTTPS requests using the fopenfamilly of functions.
为此,PHP 需要一个“包装器”来发送 HTTPS 请求——您的系统上似乎没有安装它;这意味着您不能使用fopen函数家族发送 HTTPS 请求。
For more informations about stream wrappers, if you are curious, you can take a look at List of Supported Protocols/Wrappers, and, in your case, HTTP and HTTPS.
有关流包装器的更多信息,如果您感到好奇,可以查看List of Supported Protocols/Wrappers,以及在您的情况下,HTTP 和 HTTPS。
You'll either have to install the HTTPs wrapper -- on Windows, I have no idea how to do that, unfortunately...
你要么必须安装 HTTPS 包装器——在 Windows 上,我不知道如何做到这一点,不幸的是......
Or you'll have to use something else that file_get_contentsto send your HTTPS request -- I would use the functions provided by the curlextension (Here, too, not sure it will work "out of the box", though :-( ).
或者你必须使用其他东西file_get_contents来发送你的 HTTPS 请求——我会使用curl扩展提供的功能(在这里,也不确定它是否可以“开箱即用”,但 :-( )。
For an example, you can take a look at what's proposed on the manual page of curl_exec:
例如,您可以查看以下手册页上的建议curl_exec:
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
Note you'll probably have to set a couple more options, using curl_setopt-- you should go through that page : there are a lot of useful options ;-)
请注意,您可能需要设置更多选项,使用curl_setopt- 您应该浏览该页面:有很多有用的选项;-)
As a sidenote, you are using this line at the beginning of your script :
作为旁注,您在脚本的开头使用了这一行:
$creds = parse_ini_file('/etc/aws.conf');
The path /etc/aws.conffeels strange, as you said you are using a Windows system : this looks like the kind of path one would use on an UNIX/Linux system.
这条路径/etc/aws.conf感觉很奇怪,正如您所说,您使用的是 Windows 系统:这看起来像是在 UNIX/Linux 系统上使用的那种路径。
回答by n611x007
Open php.ini. Find this line:
打开php.ini。找到这一行:
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; ...
;extension=ext/php_oci8.dll
extension=ext/php_openssl.dll ; <---- you want this
;extension=ext/php_pdo_firebird.dll
; ...
you want to uncomment the extension=ext/php_openssl.dllline. Make sure there is a pho_openssl.dllfile in the ext/directory, relative to your php.ini(or maybe more importantly to the extension_dirvariable in the ini).
您想取消注释该extension=ext/php_openssl.dll行。确保目录中有一个pho_openssl.dll文件ext/,相对于您的php.ini(或者更重要的extension_dir是相对于 ini 中的变量)。
回答by heinkasner
Simple. I had this error and gave me such headaches. Enable (uncomment the line extension=php_openssl.dll) in your php.ini file. This will solve the issue.
简单的。我有这个错误,让我很头疼。extension=php_openssl.dll在 php.ini 文件中启用(取消注释该行)。这将解决问题。

