PHPCrawl 无法创建 SSL 套接字

标签 php sockets ssl https web-crawler

我正在尝试使用 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仍然为假。

该方法的文档说明如下:

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/

相关文章:

django - 在 Mac OSX 上启用 TLS 1.2

c++ - 快速获取客户数据

mysql - 如何通过 SSL 连接将 Django 连接到 MySQL 数据库?

php - WordPress 自定义发布元 JSON 字符串不会用 json_decode() 解码

iphone - 简单的Iphone客户端连接到服务器

php - 如何在单个文件上强制使用 HTTPS? (PHP)

sockets - 一端的套接字上的 close() 是否也会在另一端关闭?

c++ - C 服务器 - "The connection was reset"

PHP include() 替代方案?

php - 如何在不刷新的情况下更改页面内容