I'm totally disappointed. I am connecting to a ssl servers, and direct connections working well, but when I am trying to add stream context to use proxy or socks5, socket won't use it and connecting pretty well directly to these ssl:// server anyway, I am checking by watching 127.0.0.1 proxy server log - there weren't even connection attempts. Also, could I wrap stream into socks5 server using socks5:// http proxy option?
$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);
I've found the right way. This connects thru socks5 servers perfectly.