0

That is the script I have

<?php
    $timeout = 10;
    $target = "tls://testbed-epp.nominet.org.uk:700";

    $result = stream_socket_client($target, $errno, $errstr, 30, STREAM_CLIENT_CONNECT);
    if ($result === False) {
        throw new Exception("Error connecting to $target: $errstr (code $errno)");

    }

    echo "Connected";

And it throws an exception

Error connecting to tls://testbed-epp.nominet.org.uk:700: (code 0)

There is also a warning

WARNING: stream_socket_client(): Failed to enable crypto

At the same time running

 openssl s_client -connect testbed-epp.nominet.org.uk:700

in a terminal connects flawlessly.

Any ideas will be appreciated

3 Answers 3

1

Try this instead:

$result = stream_socket_client("testbed-epp.nominet.org.uk:700", $errno, $errstr);

EDIT: also you can setup secure connection via stream_socket_enable_crypto() function, but you should note that it must be used AFTER initialization of socket connection.

Sign up to request clarification or add additional context in comments.

1 Comment

Strangely it works without specifying the protocol. The problem is I can not edit that file because it is a third-party library. Besides that the same script works on another server just fine so there is something with the server configuration I suppose. My original concern was that in runs through VPN client installed on a VM node in a remote server. But as it turns out that's not the issue
1

Well, i tested your code on my apache server, and it is working fine. Can you check your apache configs. In the configs there is a parameter called "Registered Stream Socket Transports ". Just check if tls exists as a value over there, else there is some other problem, but it definitely isn't your script

5 Comments

Doing phpinfo() shows that Registered Stream Socket Transports tcp, udp, unix, udg, ssl, sslv3, sslv2, tls
ok, this is strange but i noticed in your error above the $errstr is empty. You should have something. I tried changing the port and it gave me connection refused. Similarly, you should have something for this error
The thing is it is empty and the error code is 0. On my original script error logging catches a warning - WARNING: stream_socket_client(): Failed to enable crypto. I updated the question. Probably the reason warning was not shown in the test script is the fact I ran it through command line
do you have openssl extension enabled in your configs? I just realised i have openssl support enabled on apache.
It is enabled. If you are talking about httpd.conf LoadModule
0
$timeout =- 10;
          ^----

You're setting $timeout to be negative 10 seconds. e.g. you're killing the connection attempt before it can EVER get started.

2 Comments

Thanks for the reply, it was a typo and in the original script it is positive. So this is not the reason I am afraid
And the variable is not used, a hardcoded timeout of 30 is instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.