walkor / phpsocket.io

A server side alternative implementation of socket.io in PHP based on workerman.
2.3k stars 508 forks source link

RFC6455 Socket implementation incompatible with ProtocolInterface #288

Closed PhilLehmann closed 1 year ago

PhilLehmann commented 1 year ago

Hello together,

after starting my phpsocket.io-implementation ("workerman/phpsocket.io": "1.1.17" and "workerman/phpsocket.io-emitter": "1.0.2"), I receive the following output as soon as I try to connect with a call to (io('http://localhost:2020'); using "socket.io-client": "2.5.0") :

----------------------- WORKERMAN -----------------------------
Workerman version:4.1.10          PHP version:8.2.4
------------------------ WORKERS -------------------------------
worker                        listen                              processes status
PHPSocketIO          socketIO://0.0.0.0:2020             1         [ok]
PHP Fatal error:  Declaration of PHPSocketIO\Engine\Protocols\WebSocket\RFC6455::input(string $buffer, Workerman\Connection\ConnectionInterface $connection): int|bool must be compatible with Workerman\Protocols\ProtocolInterface::input($recv_buffer, Workerman\Connection\ConnectionInterface $connection) in D:\Projekte\fiddle\api\vendor\workerman\phpsocket.io\src\Engine\Protocols\WebSocket\RFC6455.php on line 47

Fatal error: Declaration of PHPSocketIO\Engine\Protocols\WebSocket\RFC6455::input(string $buffer, Workerman\Connection\ConnectionInterface $connection): int|bool must be compatible with Workerman\Protocols\ProtocolInterface::input($recv_buffer, Workerman\Connection\ConnectionInterface $connection) in D:\Projekte\fiddle\api\vendor\workerman\phpsocket.io\src\Engine\Protocols\WebSocket\RFC6455.php on line 47
Worker process terminated with ERROR: E_COMPILE_ERROR "Declaration of PHPSocketIO\Engine\Protocols\WebSocket\RFC6455::input(string $buffer, Workerman\Connection\ConnectionInterface $connection): int|bool must be compatible with Workerman\Protocols\ProtocolInterface::input($recv_buffer, Workerman\Connection\ConnectionInterface $connection) in D:\Projekte\fiddle\api\vendor\workerman\phpsocket.io\src\Engine\Protocols\WebSocket\RFC6455.php on line 47"

In a little bit more readable format:

Declaration of 
PHPSocketIO\Engine\Protocols\WebSocket\RFC6455::input(string $buffer, Workerman\Connection\ConnectionInterface $connection): int|bool 
must be compatible with 
         Workerman\Protocols\ProtocolInterface::input($recv_buffer, Workerman\Connection\ConnectionInterface $connection)
in 
         <...>\vendor\workerman\phpsocket.io\src\Engine\Protocols\WebSocket\RFC6455.php 
on line 47

Am I doing something wrong? To be honest it just looks like a book that everyone should stumble upon.

PhilLehmann commented 1 year ago

Basically, only the types for the first parameters of the following three methods were missing. When I add them locally in file workerman\workerman\Protocols\ProtocolInterface.php, it works fine:

interface ProtocolInterface
{
    /**
     * Check the integrity of the package.
     * Please return the length of package.
     * If length is unknow please return 0 that mean wating more data.
     * If the package has something wrong please return false the connection will be closed.
     *
     * @param string              $recv_buffer
     * @param ConnectionInterface $connection
     * @return int|false
     */
    public static function input(string $recv_buffer, ConnectionInterface $connection);

    /**
     * Decode package and emit onMessage($message) callback, $message is the result that decode returned.
     *
     * @param string              $recv_buffer
     * @param ConnectionInterface $connection
     * @return mixed
     */
    public static function decode(string $recv_buffer, ConnectionInterface $connection);

    /**
     * Encode package brefore sending to client.
     * 
     * @param mixed               $data
     * @param ConnectionInterface $connection
     * @return string
     */
    public static function encode(mixed $data, ConnectionInterface $connection);
}