我正在尝试使用 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/