Elephant.io Client not working

Lion picture Lion · Jan 6, 2015 · Viewed 8.6k times · Source

I've a socket.io based Websocket-Server which should get notifications from a php application. I found http://elephant.io/ which seems to be the right library for doing this. It seems that elephant.io is optimized for composer because i can't find any example for using it without them and by trying it on my own I get endless errors of includes files which are missing.

So I installed composer the first time and the elephant.io packet in the folder lib\composer so all files of this library are located in lib\composer\vendor\wisembly. The example from http://elephant.io/#usage is not working because the constructor of the Client doesn't accept these parameters. It has only two arguments and the first one must be a instance of ElephantIO\EngineInterface so I tried the following:

error_reporting(E_ALL);
ini_set('display_errors', true);

require_once __DIR__ . '/lib/composer/vendor/autoload.php';

use ElephantIO\Client as Elephant;
use ElephantIO\Engine\SocketIO as Version1X;

$elephant = new Elephant(new Version1X('http://mywsserver.com:8000'));

$elephant->init();
$elephant->send(
    ElephantIOClient::TYPE_EVENT,
    null,
    null,
    json_encode(array('name' => 'foo', 'args' => 'bar'))
);
$elephant->close();

echo 'tryin to send `bar` to the event `foo`';

But its also not working:

Fatal error: Class 'ElephantIO\Engine\SocketIO' not found in C:\inetpub\wwwroot\test.php on line 11

I'm new to composer but for me it seems that this system should be handling all the including-stuff by including the autoloader-file.

I just want to send notifications from a php-app to a socket.io server, it seems very hard to do that. The only alternative I found is https://github.com/rase-/socket.io-php-emitter but this one required redis. I wouldn't like this because I'm using Windows and my application wouldn't profit from redis because I have only one server.

Isn't there an easy way to do this? I used phpws before I'm using socket.io, this worked perfectly, but socket.io seems to be a better solution instead of the .NET library I used as server before, so I would prefer to keep on socket.io.

Answer

Dslayer picture Dslayer · Jan 7, 2015

I used ElephantIO before and what I did was create my own php autoloader. composer should have done it but can't see where you went wrong from the code. Anyway this was my autoloader.php

require_once("src/Client.php");
require_once("src/EngineInterface.php");
require_once("src/AbstractPayload.php");
require_once("src/Exception/SocketException.php");
require_once("src/Exception/MalformedUrlException.php");
require_once("src/Exception/ServerConnectionFailureException.php");
require_once("src/Exception/UnsupportedActionException.php");
require_once("src/Exception/UnsupportedTransportException.php");

require_once("src/Engine/AbstractSocketIO.php");
require_once("src/Engine/SocketIO/Session.php");
require_once("src/Engine/SocketIO/Version0X.php");
require_once("src/Engine/SocketIO/Version1X.php");
require_once("src/Payload/Decoder.php");
require_once("src/Payload/Encoder.php");