As Daniel J has pointed out, stream_socket_shutdown doesn't send the TLS close_notify message. In some instances, it's a preferred function over fclose (to trigger stream_select, for example).
To use this function correctly with TLS, use stream_socket_enable_crypto($fp, false); before shutting down the socket.