phpsocket.io icon indicating copy to clipboard operation
phpsocket.io copied to clipboard

Listen to PHP Events from other script

Open henrikthorn opened this issue 10 years ago • 1 comments

Would there be a way to use PHP to send an event to the server, which will emit the message to the clients?

I could be something like this:

$i = 0; while($i <= 1000){ echo $i."\n"; $i++; $messageEvent = new Event\MessageEvent(); $messageEvent->setMessage(array( 'event' => 'addme', 'message' => "Count $i", )); $messageEvent->setEndpoint(null); $dispatcher = Event\EventDispatcher::getDispatcher(); $dispatcher->dispatch("server.addme", $messageEvent, null); sleep(1); }

I wish to build an application that reacts on events in PHP and pushes these through socketio. I think the best way would be to integrate this in the server, instead of having a client that'll post it to the server, who will need to handle the events.

henrikthorn avatar Oct 14 '15 14:10 henrikthorn

There's no php socketio client side implements. But you can send a event over websocket or simple HTTP POST.

Here is the socketio protocol spec.

https://github.com/socketio/socket.io-protocol

RickySu avatar Oct 15 '15 01:10 RickySu