Ça trompe énormément

Related tags

Event elephant.io
Overview

Elephant.io

Build Status Latest Stable Version Total Downloads License

        ___     _,.--.,_         Elephant.io is a rough websocket client
      .-~   ~--"~-.   ._ "-.     written in PHP. Its goal is to ease the
     /      ./_    Y    "-. \    communications between your PHP Application and
    Y       :~     !         Y   a real-time server.
    lq p    |     /         .|
 _   \. .-, l    /          |j   Requires PHP 5.4 and openssl, licensed under
()\___) |/   \_/";          !    the MIT License.
 \._____.-~\  .  ~\.      ./
            Y_ Y_. "vr"~  T      Built-in Engines :
            (  (    |L    j      - Socket.io 2.x
            [nn[nn..][nn..]      - Socket.io 1.x
          ~~~~~~~~~~~~~~~~~~~    - Socket.io 0.x (courtesy of @kbu1564)

NOTICE

As we are not using Elephant.io anymore at Wisembly, and not having the time to maintain this library, we are looking for maintainers. Please look at the dedicated issue #135 !

Installation

We are suggesting you to use composer, with the following : php composer.phar require wisembly/elephant.io. For other ways, you can check the release page, or the git clone urls.

Documentation

The docs are not written yet, but you should check the example directory to get a basic knowledge on how this library is meant to work.

Special Thanks

Special thanks goes to Mark Karpeles who helped the project founder to understand the way websockets works.

Comments
  • initialize() method start a processes without ends

    initialize() method start a processes without ends

    Hello!

    I can connect on my Socket Server with this library, but the method initialize() never ends on browser... It keep a proccess running and dont call the next methods ( emit() and close() ).

    How can I solve that?

    $client = new Client(new Version2X('https://myurl.com:2021', [
      'context' => [
        'ssl' => [
          'verify_peer' => false,
          "verify_peer_name"=>false,
          'allow_self_signed'=> false
        ]
      ]
    ]));
          
    $client->initialize();
    $client->emit('alert', 'Hello world!');
    $client->close();
    

    Thanks a lot!

    support 
    opened by alissonpelizaro 23
  • Handshake fails if server restricts origins

    Handshake fails if server restricts origins

    Hi,

    I've a node socket.io server (using https) to which both JS and PHP clients connect. Everything is fine until I restrict the server to some origins : the JS clients can connect but not the php anymore.

    After some digging, I see that the handshake is failing because it uses file_get_contents without setting the origin. If I force the origin it seems to works correctly :

    $context['http'] = ['timeout' => (float) $this->options['timeout'], 'header' => 'Origin: https://some.domain.com'];
    

    Maybe it's a good idea to also let the user to set the origin as an option (default to *) ? Something like :

    new ElephantIO\Client(
        new ElephantIO\Engine\SocketIO\Version1X(
            'https://my.server.com:12345?param1=value1',
            array('origin' => 'https://some.domain.com')
        )
    );
    

    In this case, the origin is properly set in the handshake and upgradeTransport Vincent

    improvement bug recommendation 
    opened by vincentdieltiens 21
  • socket.io from v1.0.x return error on handshake

    socket.io from v1.0.x return error on handshake

    When enabling curl verbose during the handshake I can see that socket.io is returning an HTTP 400:

    * Adding handle: conn: 0x7fd781809000
    * Adding handle: send: 0
    * Adding handle: recv: 0
    * Curl_addHandleToPipeline: length: 1
    * - Conn 1 (0x7fd781809000) send_pipe: 1, recv_pipe: 0
    * About to connect() to acme.local port 3700 (#1)
    *   Trying 127.0.0.1...
    * Connected to acme.local (127.0.0.1) port 3700 (#1)
    > GET /socket.io/1 HTTP/1.1
    Host: acme.local:3700
    Accept: */*
    
    < HTTP/1.1 400 Bad Request
    < Content-Type: application/json
    < Date: Mon, 02 Jun 2014 01:39:33 GMT
    < Connection: keep-alive
    < Transfer-Encoding: chunked
    < 
    * Connection #1 to host acme.local left intact
    

    Directly hitting the nodejs server in the browser: http://acme.local:3700/socket.io/1

    {
        code: 0,
        message: "Transport unknown"
    }
    

    I think it's missing some parameters in the handshake query. I'm using the master branch. I'll try to switch to 2.0.x to see if it change something.

    opened by Maxwell2022 16
  • Socket.IO 1.x namespaces

    Socket.IO 1.x namespaces

    I implemented for Socket.IO 1.x namespaces in Elephant.IO. They are tested in production and do their job. Also i added small example for usage under example/socket.io/1.x/emitter_namespace . Its still possible to use Elephant.IO with default namespace and should be compatible with previous versions. The usage is simple - controller has 3. parameter the namespace. If there is interest in this functionality i could also provide similar solution for Socket.IO 0.x version.

    $client = new Client(new Version1X('http://localhost:1337', '/test'));
    
    $client->initialize();
    $client->emit('broadcast', ['foo' => 'bar']);
    $client->close();
    
    1. parameter is optional.
    // Namespace resolves to default one - "/" .
    $client = new Client(new Version1X('http://localhost:1337'));
    
    $client->initialize();
    $client->emit('broadcast', ['foo' => 'bar']);
    $client->close();
    
    
    improvement 
    opened by JanisGruzis 15
  • Little patch for Socket 1.0.x - Working on my nRelay Project.

    Little patch for Socket 1.0.x - Working on my nRelay Project.

    I spent a little time today to have Elephant.IO working with Socket 1.0.x. Only tested with the default namespace "/" but it works for me

    Hope it helps ! Thanks for this project.

    opened by lalmat 14
  • Emitter via HTTPS

    Emitter via HTTPS

    I try to sent to:

    <?php
    $client = new Client(new Version1X('http://sitename:7999'));
    

    It's ok

    But I try:

    <?php
    $client = new Client(new Version1X('https://sitename:7999'));
    

    And get the exception.

    Warning: in_array() expects parameter 2 to be array, null given in \project\vendor\wisembly\elephant.io\src\Engine\SocketIO\Version1X.php on line 172
    
    Fatal error: Uncaught ElephantIO\Exception\UnsupportedTransportException: This server does not support the websocket transport, aborting in \project\vendor\wisembly\elephant.io\src\Engine\SocketIO\Version1X.php:173 Stack trace: #0 \project\vendor\wisembly\elephant.io\src\Engine\SocketIO\Version1X.php(48): ElephantIO\Engine\SocketIO\Version1X->handshake() #1 \project\vendor\wisembly\elephant.io\src\Client.php(60): ElephantIO\Engine\SocketIO\Version1X->connect() #2 \project\elephant.php(20): ElephantIO\Client->initialize() #3 {main} thrown in \project\vendor\wisembly\elephant.io\src\Engine\SocketIO\Version1X.php on line 173
    
    support 
    opened by psprokofiev 13
  • SocketIO 1.x connect problem.

    SocketIO 1.x connect problem.

    Hi,

    https://github.com/Wisembly/elephant.io/blob/master/src/Engine/SocketIO/Version1X.php#L182

    Sometimes this exception is thrown, I cannot really figure out why... seems random. (The server is up, and even receives the emmitted data).

    Any help would be much appreciated.

    improvement bug support 
    opened by Padam87 13
  • Unable to connect to my server

    Unable to connect to my server

    I have an Api Rest in symfony. I wanna push some message with Elephant but evrey time di try to connect symfony to my Server Node, it returns this message {"code":500,"message":"An error occurred while trying to establish a connection to the server"}

    Here is my symfony code:

    <?php
    
    /**
       * @Rest\View()
       * @Rest\Get("/users")
    */
    public function listerLesUtilisateursAction( Request $request ){
    
        $client = new Client(new Version1X('http://battle-push-test.webmobilexpert.com'));
    		
        $client->initialize();
        $client->emit('test', ['foo' => 'bar']);
        $client->close();		
        return true;
            
    }
    
    

    Here is my server code:

    var app = require( 'express' )();
    var server = require( 'http' ).createServer( app );
    var io = require( 'socket.io' ).listen( server );
    
    var port = process.env.PORT || 8080;
    
    
    app.get('/', function (req, res) {
      res.end("Server works fine" );
    });
    
    io.sockets.on( 'connection', ( socket ) => {
        
       //Wen client connects, send a test message
        socket.on( 'test', ( datas ) => {
            socket.broadcast.emit( 'connect_message', 'Vous êtes connecté au serveur push avec succès wi' );
    
        });
    });
    

    Help me please, it's two weeks that i try to resolve this :(

    support 
    opened by flaatpixels 12
  • Can't connect to the server when using SSL

    Can't connect to the server when using SSL

    Hi,

    I keep getting this issue everytime I try connecting using the SSL. But it works fine without SSL.

    ElephantIO\Exception\ServerConnectionFailureException. I am using the following code

    
           $client = new Client(new Version1X("https:://www.mydomainname.com:3000"));
            $client->initialize();
            $client->emit("test", ["key"=> "val"]);
            $client->close();
    
    

    Any helpp would be really appreciated.

    support 
    opened by eldan88 12
  • socket.io payload decoder support

    socket.io payload decoder support

    add method decodePayload() of ElephantIO/Payload.php add method of Singleton pattern instance

    use :

    <?php
    // ElephantIo/Payload.php
    class Payload
    {
        ....
        /**
         * @return Payload
         * Singleton Pattern
         */
        public function getInstance() {
            static $obj = null;
            if ($obj == null) $obj = new Payload();
    
            return $obj;
        }
        ....
    }
    ?>
    
    <?php
    $payload = &Payload::getInstance();
    $payload->setPayload($encodingPayloadData);
    echo $payload->decodePayload()."\n";
    ?>
    
    opened by kbu1564 12
  • Client receives two messages even if only one was sent.

    Client receives two messages even if only one was sent.

    When I send a message/event from PHP, my client receives two messages instead of one.

    PHP code: $s = $elephant->send( ElephantIO\Client::TYPE_EVENT, null, null, json_encode(array('name' => 'event_name', 'args' => array('...'))) );

    Node.js code: socket.on ('event_name', function (data) {
    socket.broadcast.emit('another_event', data.msg, data.id_booking); console.log("Event triggered "+data.msg); });

    Client code: socket.on('another_event', function (msg, id_booking) { alert("Another event triggered!"); });

    On the client I get two alerts instead of just one. What could be the problem?

    I mention that I transfer other messages too but without elephant.io and everything works ok. Just this example has this issue, that's why I suspect it's something about elephant.io

    Thanks in advance, Stef

    opened by stevro 11
  • UnexpectedValueException

    UnexpectedValueException "The server returned an unexpected value. Expected "HTTP/1.1 101", had "HTTP/1.1 400"" #217

    #message: "The server returned an unexpected value. Expected "HTTP/1.1 101", had "HTTP/1.1 400"" #file: "..project_dir/vendor/wisembly/elephant.io/src/Engine/SocketIO/Version1X.php" #line: 266

    My Code:

    $io_client = new Client(new Version2X(config('app.socket_url')));
    $io_client->initialize();
    $io_client->emit('clientMessage', $data);
    $io_client->close();
    

    Thanks

    opened by UpKing98 3
  • Using Version2X but getting a Version1X error ?

    Using Version2X but getting a Version1X error ?

    Hi, I'm trying to emit an event from a php controller with elephant io by using version2X but I get a version1x error. Here is what my code looks like :

    $socket = env('HTTP_PROTOCOL').'://'.env('URL_SOCKET').':'.env('PORT_SOCKET_MESSAGES');
                            $client = new Client(new Version2X($socket));
                            $client->initialize();
                            $client->emit('message', [
                                'message' => 'some message',
                            ]);
                            $client->close();
    

    It works on my local machine (using wamp) but does not on the dev server.

    It return me this error :

    "name": "PHP Warning",
        "message": "file_get_contents(<my_url>/socket.io/?use_b64=0&amp;EIO=3&amp;transport=polling): failed to open stream: Connection refused",
        "code": 2,
        "type": "yii\\base\\ErrorException",
        "file": "<app_url>/vendor/wisembly/elephant.io/src/Engine/SocketIO/Version1X.php",
        "line": 177,
        "stack-trace": [
            "#0 [internal function]: yii\\base\\ErrorHandler->handleError(2, 'file_get_conten...', '<root_url>/...', 177, Array)",
            "#1 <app_url>/vendor/wisembly/elephant.io/src/Engine/SocketIO/Version1X.php(177): file_get_contents('<url>', false, Resource id #39)",
            "#2 <app_url>/vendor/wisembly/elephant.io/src/Engine/SocketIO/Version1X.php(48): ElephantIO\\Engine\\SocketIO\\Version1X->handshake()",
            "#3 <app_url>/application/vendor/wisembly/elephant.io/src/Client.php(60): ElephantIO\\Engine\\SocketIO\\Version1X->connect()",
            "#4 <app_url>/application/controllers/ApiController.php(382): ElephantIO\\Client->initialize()",
            "#5 [internal function]: app\\controllers\\ApiController->actionMessages('940833739', '701165609')",
            "#6 <app_url>/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)",
            "#7 <app_url>/vendor/yiisoft/yii2/base/Controller.php(178): yii\\base\\InlineAction->runWithParams(Array)",
            "#8<app_url>/vendor/yiisoft/yii2/base/Module.php(552): yii\\base\\Controller->runAction('messages', Array)",
            "#9<app_url>/vendor/yiisoft/yii2/web/Application.php(103): yii\\base\\Module->runAction('api/messages', Array)",
            "#10<app_url>/vendor/yiisoft/yii2/base/Application.php(384): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))",
            "#11 <root_url>/index.php(24): yii\\base\\Application->run()",
            "#12 {main}"
        ]
    

    Do you know why it would use Version1X although I'm using Version2X and why this error happens ?

    opened by ThibaultMagy 4
  • suddenly can't establish connection with server

    suddenly can't establish connection with server

    hi all,

    i use elephant to emit to events messages to a AWS EC2 server, everything was working fine until now, suddenly this stopped working properly. for some reason that I can't explain the connection to the server is being refused. here is the error I've been receiving. curiosity, the connection through client and the socket.io server is still working...

    this is been super block on a live project, let me know what I can do.

    
    object(ElephantIO\Exception\ServerConnectionFailureException)#21 (8) {
      ["errorMessage":"ElephantIO\Exception\ServerConnectionFailureException":private]=>
      NULL
      ["message":protected]=>
      string(70) "An error occurred while trying to establish a connection to the server"
      ["string":"Exception":private]=>
      string(0) ""
      ["code":protected]=>
      int(0)
      ["file":protected]=>
      string(78) "/var/app/current/vendor/wisembly/elephant.io/src/Engine/SocketIO/Version1X.php"
      ["line":protected]=>
      int(187)
      ["trace":"Exception":private]=>
      array(3) {
        [0]=>
        array(6) {
          ["file"]=>
          string(78) "/var/app/current/vendor/wisembly/elephant.io/src/Engine/SocketIO/Version1X.php"
          ["line"]=>
          int(48)
          ["function"]=>
          string(9) "handshake"
          ["class"]=>
          string(36) "ElephantIO\Engine\SocketIO\Version1X"
          ["type"]=>
          string(2) "->"
          ["args"]=>
          array(0) {
          }
        }
        [1]=>
        array(6) {
          ["file"]=>
          string(59) "/var/app/current/vendor/wisembly/elephant.io/src/Client.php"
          ["line"]=>
          int(60)
          ["function"]=>
          string(7) "connect"
          ["class"]=>
          string(36) "ElephantIO\Engine\SocketIO\Version1X"
          ["type"]=>
          string(2) "->"
          ["args"]=>
          array(0) {
          }
        }
        [2]=>
        array(6) {
          ["file"]=>
          string(29) "/var/app/current/web/hugo.php"
          ["line"]=>
          int(28)
          ["function"]=>
          string(10) "initialize"
          ["class"]=>
          string(17) "ElephantIO\Client"
          ["type"]=>
          string(2) "->"
          ["args"]=>
          array(0) {
          }
        }
      }
      ["previous":"Exception":private]=>
      NULL
    }
    NULL
    
    
    opened by hugoalexmartins 4
  • did someone tried to use it with socket.io version 4x ?

    did someone tried to use it with socket.io version 4x ?

    Hello,

    I tried no error but i no received message

    class Version4X extends \ElephantIO\Engine\SocketIO\Version1X
    {
    
        /** {@inheritDoc} */
        public function getName()
        {
            return 'SocketIO Version 4.X';
        }
    
        /** {@inheritDoc} */
        protected function getDefaultOptions()
        {
            $defaults = parent::getDefaultOptions();
    
            $defaults['version'] = 4;
    
            return $defaults;
        }
    }
    
    
    function sendToSocket()
    {
        $client = (new Client(new Version4X('https://127.0.0.1:7777', [
            'debug' => true,
            'version' => 4,
            'query' => ['username' => 'toto', 'connectionType' => 'browser-client']
        ])))->initialize();
        // send message to connected clients
        $client->emit('broadcast', ['type' => 'notification', 'text' => 'Hello There!']);
        $client->close();
    }
    try {
        sendToSocket();
    } catch (ServerConnectionFailureException $e) {
        dump($e->getErrorMessage());
    } catch (\Exception $e) {
        dump($e);
    }
    echo "ok";
    

    nodejs server side

    
    server.listen(port, '0.0.0.0',() => {
        console.info(`ℹ local nodejs server started on https://${domain}:${port}`)
    })
    
    io.on("connection", socket => {
        socket.on('broadcast', function (message) {
            console.info('ElephantIO broadcast > ' + JSON.stringify(message));
    
            // send to all connected clients
            io.sockets.emit("broadcast", message);
        });
    });
    
    opened by filoucrackeur 1
  • Fatao Error: ServerConnectionFailureException

    Fatao Error: ServerConnectionFailureException

    Hello sorry i know this will be a basic answer but i've been digging around online for hours and can't find anything to solve it.

    I'm getting the follow error:

    [17-May-2021 12:21:39 UTC] PHP Fatal error:  Uncaught ElephantIO\Exception\ServerConnectionFailureException: An error occurred while trying to establish a connection to the server in /Users/#/html/sockets/vendor/wisembly/elephant.io/src/Engine/SocketIO/Version1X.php:187
    Stack trace:
    #0 /Users/#/html/sockets/vendor/wisembly/elephant.io/src/Engine/SocketIO/Version1X.php(48): ElephantIO\Engine\SocketIO\Version1X->handshake()
    #1 /Users/#/html/sockets/vendor/wisembly/elephant.io/src/Client.php(60): ElephantIO\Engine\SocketIO\Version1X->connect()
    #2 /Users/#/html/sockets/emit.php(12): ElephantIO\Client->initialize()
    #3 {main}
      thrown in /Users/#/html/sockets/vendor/wisembly/elephant.io/src/Engine/SocketIO/Version1X.php on line 187
    

    (filepath removed for privacy)

    I did search through existing issues and found something similar at the URL below but it didn't - to me atleast - provide a solution.

    https://github.com/Wisembly/elephant.io/issues/179

    the code im using to initialize is as follows:

    include ("vendor/autoload.php");
    use ElephantIO\Client;
    use ElephantIO\Engine\SocketIO\Version2X;
    $version = new Version2X("http://localhost:3001");
    $client = new Client($version);
    $client->initialize();
    $client->emit("new_order", ["test"=>"test","test1"=>"test1"]);
    $client->close();
    

    Any help would be incredibly appreciated.

    All the best, Coinstacker Team

    opened by CoinStacker 2
Releases(v3.3.0)
  • v3.3.0(May 9, 2017)

    This is a new version for ElephantIO, bringing basic support for SocketIO 2.0.

    Here is a basic changelog, you may find the full diff here : https://github.com/Wisembly/Elephant.IO/compare/v3.2.0...3.3.0.

    Changelog

    Features

    • #152 : Support for SocketIO 2.0 (Thanks @SeinopSys)

    A quick reminder : we are still looking for maintainers. For that, see #135. :}

    Source code(tar.gz)
    Source code(zip)
  • v3.2.0(Oct 25, 2016)

    This is a new version for ElephantIO, bringing a new feature, and a bunch of bugfixes (it's pretty small actually). Here is a basic changelog, you may find the full diff here : https://github.com/Wisembly/Elephant.IO/compare/v3.1.0...3.2.0.

    Changelog

    Features

    • #145 : Cookie support in handshake (Thanks @neanton)

    Bugfixes

    • #141 : Fix a missing use statement (thanks @lattwood)
    • #138 : Fix query args handling when the path is not set or is / (thanks @titanco)

    A quick reminder : we are still looking for maintainers. For that, see #135. :}

    Source code(tar.gz)
    Source code(zip)
  • 3.1.0(Mar 23, 2016)

    This is a new version for ElephantIO, bringing some new (awesome ?) features. Here is a basic changelog, you may find the full diff here : https://github.com/Wisembly/Elephant.IO/compare/v3.0.0...3.1.0.

    Changelog

    Features

    • #104 Namespaces support (thanks @vincentdieltiens)
    • #103 Supports headers when sending upgrade transport request (thanks @vincentdieltiens)

    Bugfixes

    • #95 Fixes the SSL handshakes (thanks @lalmat)
    • #106, #118 Fixes the read method (thanks @jrdiaz, @mshaverdo)
    • #108 Reset session when disconnecting the client (fixes #107, thanks @Padam87)
    • #103 Better handling of http / ssl contexts (fixes #81, thanks @vincentdieltiens)
    • #103 Send a close frame on connection close (thanks @vincentdieltiens)

    Thanks

    For this release, I'd like to thank @vincentdieltiens for the work he did on the namespaces and the context handling and @jrdiaz for improving the status on the read() method, and of course everybody who did minor fixes (Even typos !) allows us to go even further !

    Source code(tar.gz)
    Source code(zip)
  • v3.0.0(Sep 8, 2014)

    After some releases, v3.0 of Elephant.io is (finally) here. The whole architecture of the project was changed, and is now following the PSR-4 autoloading principle.

    • Socket.io 1.x compatibility
    • Engine abstraction, meaning that you can implement another engine for your messages, such as using RabbitMQ, Reddis, ... etc instead of good old Socket.io ; Socket.io 1.x and Socket.io 0.x are built-ins.
    • Wrapper around the Engine abstraction
    • Refactored the Payload classes, and split them up into several classes (one for decoding, and one for encoding payloads)
    • Dropped curl utilisation, used php's stream api instead

    This should make a rough idea of what is implemented in this new version.

    (Yup, this is a stupid copy and paste from the first beta)

    Source code(tar.gz)
    Source code(zip)
  • v3.0.0-RC2(Sep 1, 2014)

    It would appear the previous release was not stable enough to be considered as a gold release ; this one should be the one. I hope. Anyway, here is what was changed since last time :

    • Fix #69 : error on the replacing of unexistant $query in a array_replace call on Socket.io version 0.x (fixed by @kbu1564 in #70)
    • Fix a warning if the connection to the socket.io server cannot be done ; an exception is thrown instead, and the error is now silent.
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0-RC(Aug 29, 2014)

    A few fixes since the beta2 :

    • Socket.io v0.x adapter (courtesy of @kbu1564 in #62)
    • Better handling of the url parsing (courtesy of @kcahir in #65)

    This should be the golden release, and is marked as stable enough to be used in prod.

    Source code(tar.gz)
    Source code(zip)
  • v3.0.0-beta2(Aug 13, 2014)

    A few bug fixes since the beta 1 :

    • Refs #18 : split the packet in case of its length > 16kb
    • Reverse parameters order when building the url
    • Add a timeout on the handshake request
    • Add a timeout on the stream socket connection
    Source code(tar.gz)
    Source code(zip)
  • v2.0.4(Aug 30, 2014)

    This new release brings some improvements and verifications on the Client

    • Event handler (courtesy of @Gounlaf & @williamklein) : #39 #36
    • Compatibility fix for curl's usage #50 #51
    • Query args on handshake (@jbaez via #34)
    • Better SSL Verification on the host (@rosko via #36)
    Source code(tar.gz)
    Source code(zip)
Ça trompe énormément

Elephant.io ___ _,.--.,_ Elephant.io is a rough websocket client .-~ ~--"~-. ._ "-. written in PHP. Its goal is to e

Wisembly 1.2k Apr 21, 2021