varspool / Wrench

A simple PHP WebSocket implementation for PHP 7.1
Do What The F*ck You Want To Public License
596 stars 210 forks source link

To hide "socket_import_stream(): cannot represent a stream of type tcp_socket/ssl as a Socket Descriptor" #126

Open manoletto opened 4 years ago

manoletto commented 4 years ago

To set the TCP_NODELAY socket option only when it is possible, and disable warning message :

socket_import_stream(): cannot represent a stream of type tcp_socket/ssl as a Socket Descriptor

in Wrench/lib/Socket/ServerSocket.php accept() method (on line 67),

i suggest this :

        if (!$new) {
            throw new ConnectionException(socket_strerror(socket_last_error($new)));
        }

++      if(($sock = @socket_import_stream($new))>0){
--      socket_set_option(socket_import_stream($new), SOL_TCP, TCP_NODELAY, 1);
++          socket_set_option($sock, SOL_TCP, TCP_NODELAY, 1);
++      }

        return $new;
manoletto commented 4 years ago

Better solution :

in Wrench/lib/Socket/ServerSocket.php getSocketStreamContextOptions() method,

add

$options['tcp_nodelay'] = TRUE;

and remove socket_set_option() call in accept() method.

It works ;-)