我完全失望了。我正在连接到 ssl 服务器,并且直接连接运行良好,但是当我尝试添加流上下文以使用代理或 socks5 时,socket 不会使用它并且无论如何都可以很好地直接连接到这些 ssl:// 服务器,我我通过观看 127.0.0.1 代理服务器日志进行检查 - 甚至没有连接尝试。另外,我可以使用 socks5:// http 代理选项将流包装到 socks5 服务器中吗?
$ctx = stream_context_create( array(
"http" => array(
"timeout" => 15,
"proxy" => "tcp://127.0.0.1:3128",
"request_fulluri" => TRUE,
),
"ssl" => array(
"SNI_enabled" => FALSE,
)
) );
try
{
$socket = stream_socket_client( "ssl://google.com:443",
$errno, $errstr, 15, STREAM_CLIENT_CONNECT, $ctx );
}
catch ( Exception $e )
{
die( $e->getMessage() );
}
if ( $socket === FALSE )
{
echo "bad socket";
}
fwrite( $socket, "GET /\n" );
echo fread( $socket, 8192 );
// Here I am connected DIRECTLY, not thru proxy. WHY ???
// But this call succesfully uses context
echo file_get_contents("https://google.com", 0, $ctx);