stream_socket_client doesn't work???

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm using PHP 5.0 on Windows XP, and I'm trying to use
stream_socket_client to attach to an SSL socket server.  Something like

$host = "localhost";
$port = 9999;

$context = stream_context_create();
stream_context_set_option($context, 'ssl', 'local_cert', 'mycert.pem');
stream_context_set_option($context, 'ssl', 'passphrase', 'secret');

$where = "ssl://$host:$port";

$s = stream_socket_client($where, $errno, $errstr, 30, 0, $context);


This code runs.  $s reports to be a stream resource, nothing is placed
in $errno or $errstr.

But it doesn't make a connection to the server.  I know for certain
because I have a breakpoint in the server at "accept" (it's in C++)
that doesn't get hit.

Now, I've been single-stepping thru PHP's source code to see what I
might be missing.  What I haven't stepped into yet is anything that
actually connects a socket to a server.  It looks rather like that
should happen in php_openssl_ssl_socket_factory (a function in
xp_ssl.c) but it's not there.

Does stream_socket_client truly not work?  I need to connect to an SSL
server and send a local certificate, which fsockopen (apparently)
doesn't allow.

Re: stream_socket_client doesn't work???

Nobody helps.  I find the answer myself.  Typical.

You have to supply the value STREAM_CLIENT_CONNECT for the 'flags'
parameter of the call to stream_client_socket (I had zero because the
two flags noted didn't apply to me).  I found that out while stepping
thru the source code of transports.c.

Apparently stream_socket_client isn't ready for prime time yet; in the
documentation it's still labelled EXPERIMENTAL, and it doesn't explain
the STREAM_CLIENT_CONNECT requirement.

Site Timeline