php-stream_context_create函数针对https请求处理
官方文档有很多例子
https://www.php.net/manual/zh/function.stream-context-create.php
但是有些旧了
当我在源码编译安装php的时候, 有脚本使用了这个函数进行https的时候报错了
Warning: fopen(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /mnt/software/php-src/pear/fetch.php on line 66
Warning: fopen(https://pear.php.net/install-pear-nozlib.phar): failed to open stream: No such file or directory in /mnt/software/php-src/pear/fetch.php on line 66`
当我查看php-src/pear/fetch.php脚本时,代码是这样的:
并没有https请求对安全认证做处理,导致无法访问链接
stackoverflow找了这个在请求头设置关闭证书的校验:
https://stackoverflow.com/questions/45273206/https-for-stream-context-create
$copt = array(
'http' => array(
'proxy' => preg_replace('/^http/i', 'tcp', $_ENV['http_proxy']),
'request_fulluri' => true,
),
'ssl' => [ // here comes the actual SSL part...
'verify_peer' => false,
'verify_peer_name' => false,
]
);
重新编译安装成功!
注意 --with-openssl ,不然发起请求会失败
丝滑.....