The Linux Page

stream_socket_client() fails with no errors...

Today I had a weird one.

The PHP function named stream_socket_client(), used to create a socket to communicate with another computer over a network, may return $errno = 0 and $errstr = "".

The PHP reference actually mentions the problem:

On failure the errno and errstr arguments will be populated with the actual system level error that occurred in the system-level connect() call. If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket. Note that the errno and errstr arguments will always be passed by reference.

As we can see, they say clearly that the function may return false without setting the error number or message. This is generally because an initialization failed. They just don't tell you what failed... and no error in the error logs either. Nothing.

So this is a difficult one to debug since you could have all sorts of reasons why that call fails the initialization.

Maybe you have an invalid $context parameter.

It could be that you need to specify where the SSL certificate are found on your computer (really that should be automatic...)

Or in my case, it was the protocol used that was not supported on the platform where PHP eFax was installed. That platform (RedHat EL7) did not understand the "tls://" protocol. Instead, it wanted to see "ssl://". Oh well! Talk about walking in the fog.

Some people also reported having problems because a certificate was missing.

Either way, if you have such an error, you'll have to test everything... until it works. Since there is no real feedback, you won't be able to do much else. Someone mentioned the possibility to use a trace and see where the error occurs, but I have not tested that. (I'm not too sure how you can do that and I don't see how that could work since the stream function is in C, not a PHP class.)

If you ran in the same situation and found yet a different solution to fix the problem, please comment below with your solution to help others with this one! Thank you.

SMS From Me Logo

SMS From Me

To automatically start one on one conversations with your online leads.