2

How can I understand the error when trying to open a socket? I get error 0, however all SSL certificate works fine.

$fp = fsockopen("ssl://cloud-messaging.bitrix24.com", 443, $errno, $errstr);
if (!$fp) {
    echo "ERROR: $errno - $errstr<br />\n: " . $errno;
    print_r($errstr);
} else {
    fclose($fp);
}

Result:

ERROR: 0 -
: 0

But it works when I try to open the socket with myself.

Maybe there is some script that will allow you to get at least some error?

sk DYLAN
  • 61
  • 6
  • Welcome to SO. Does [This Post](https://stackoverflow.com/questions/21075434/fsockopen-returning-server-error0) answer your question in any way? – Eugene Anisiutkin Mar 17 '20 at 08:54
  • `ssl://` is not a protocol. Use `$fp = fsockopen("cloud-messaging.bitrix24.com", 443, $errno, $errstr);` – Jamie_D Mar 17 '20 at 09:20
  • @Jamie_D hostname If OpenSSL support is installed, you may prefix the hostname with either ssl:// or tls:// to use an SSL or TLS client connection over TCP/IP to connect to the remote host. https://www.php.net/manual/en/function.fsockopen.php – sk DYLAN Mar 17 '20 at 11:01
  • Good catch! However, if [cloud-messaging.bitrix24.com](https://cloud-messaging.bitrix24.com) is indeed the URL you are using, you will get an error since `fsocketopen` doesn't do redirects. [See this post](https://stackoverflow.com/questions/23504713/get-final-url-from-fsockopen) – Jamie_D Mar 17 '20 at 11:10
  • @Jamie_D The problem is that this code is used by the system to test the health of sockets – sk DYLAN Mar 17 '20 at 11:37
  • If that's the case than all you may need is [socket_get_status](https://www.php.net/manual/en/function.socket-get-status.php) which is an alias of [stream_get_meta_data](https://www.php.net/manual/en/function.stream-get-meta-data.php) – Jamie_D Mar 17 '20 at 11:58
  • I added a Gist for you here using the URL: https://gist.github.com/Fliktrax/f111b10e8019da98a89cd5cd25943af7 – Jamie_D Mar 17 '20 at 12:22
  • @Jamie_D Result = null. I think the problem is that my server supports TLS1.0 and TLS1.1 https://i.imgur.com/L2jr3gB.png – sk DYLAN Mar 17 '20 at 12:33
  • You can remove that with just `SSLProtocol TLSv1.2` in your virtual host/SSL setup – Jamie_D Mar 17 '20 at 12:42

0 Answers0