Be wary of using stream_socket_shutdown with a TLS socket. The socket is closed without sending the "close_notify" message required by TLS protocol.
To correctly close a TLS socket, use fclose() instead, which internally calls OpenSSL's SSL_shutdown() function.