【发布时间】:2015-06-06 20:01:26
【问题描述】:
我正在尝试使用 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仍然是假的。
该方法的文档说明如下:
如果 errno 中返回的值为 0 并且函数返回 FALSE,则表明错误发生在 connect() 调用之前。
(见http://php.net/manual/en/function.stream-socket-client.php)
所以我尝试使用 cmets 部分中提供的示例来修改流上下文,使用 'stream_context_set_option' 将 verify_host 和 verify_peer 设置为 false - 这两者似乎都没有任何效果。
我对 PHP 或网络的复杂性不是很精通 - 有人知道吗:
- 什么条件(具体而言)会导致此调用失败? 或
- 该问题的解决方法?
我应该注意 - 我使用 Facebook (HTTPS) 作为测试服务器。
【问题讨论】:
标签: php sockets ssl https web-crawler