By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,982 Members | 1,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,982 IT Pros & Developers. It's quick & easy.

stream_socket_client doesn't work???

P: n/a
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.

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
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.

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.