gpt4 book ai didi

PHPCrawl 无法创建 SSL 套接字

转载 作者:太空宇宙 更新时间:2023-11-03 13:00:55 26 4
gpt4 key购买 nike

我正在尝试使用 PHPCrawl ( http://sourceforge.net/projects/phpcrawl/ ) 来拖网通过 HTTPS 传送的网站。

我可以看到PHPCrawlerHTTPRequest 类(openSocket 方法)中有对SSL 的支持:

// If ssl -> perform Server name indication
if ($this->url_parts["protocol"] == "https://")
{
$context = stream_context_create(array('ssl' => array('SNI_server_name' => $this->url_parts["host"])));
$this->socket = @stream_socket_client($protocol_prefix.$ip_address.":".$this->url_parts["port"], $error_code, $error_str,
$this->socketConnectTimeout, STREAM_CLIENT_CONNECT, $context);
}

问题在于对 stream_socket_client 的调用 - 尽管它返回零 error_code,并且没有 error_str,this->socket 仍然是 false。

该方法的文档说明如下:

If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call.

(参见 http://php.net/manual/en/function.stream-socket-client.php)

所以我尝试使用评论部分提供的示例来修改流上下文,使用“stream_context_set_option”将 verify_host 和 verify_peer 设置为 false - 这似乎都没有任何效果。

我不是很精通 PHP 或网络的复杂性 - 有谁知道:

  • 什么情况(具体)会导致此调用失败?或者
  • 问题的解决方法?

我应该注意 - 我正在使用 Facebook (HTTPS) 作为测试服务器。

最佳答案

我发现了问题 -

  • PHP 5.6.x 版本默认打开对等验证,显然有时找不到必要的证书 (see this bug report)

  • 解决方法是退回到 5.6 之前的 PHP 版本

关于PHPCrawl 无法创建 SSL 套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29403231/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com