Skip to content

touskar/php-socket-io-event-emitter

This branch is 6 commits ahead of, 2 commits behind psinetron/PHP_SocketIO_Client:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5751abd · Nov 17, 2017

History

22 Commits
Jun 8, 2017
Jun 8, 2017
Nov 17, 2017
Jun 12, 2017
Nov 12, 2017
Jun 8, 2017

Repository files navigation

PHP Socket Client

Fork from : https://github.com/psinetron/PHP_SocketIO_Client

install

php composer require touskar/php-socket-io-event-emitter

Php

require_once '../SocketIO.php';

$client = new SocketIO('localhost', 9001);

//connection handshake query( for auth - optional)
$client->setQueryParams([
    'token' => 'edihsudshuz',
    'id' => '8780',
    'cid' => '344',
    'cmp' => 2339
]);

$success = $client->emit('eventFromPhp', [
    'name' => 'Goku',
    'age' => '23',
    'address' => 'Sudbury, On, Canada'
]);

if(!$success)
{
    var_dump($client->getErrors());
}
else{
    var_dump("Success");
}

Node Js

var app = require('http').createServer(handler)
   var io = require('socket.io')(app);
   var fs = require('fs');
   
   app.listen(9001);
   
   function handler (req, res) {
       res.writeHead(200);
       res.end('Hello Word');
   }
   
   
   io.on('connection', function (socket) {
   
       console.log("New Connection with transport", socket.conn.transport.name);
   
       console.log('With handshake', socket.handshake);
   
   
       console.log('With query', socket.handshake.query);
   
       socket.on('eventFromPhp', function (data) {
           console.log('Data from Php', data, JSON.parse(data));
       });
   });
   

2 - API

.setMaxRetry(n)

$client->setMaxRetry(10);//default 5

.setRetryInterval(interval)

$client->setRetryInterval(100);// 100 ms, default 200

.setProtocole(protocol)

$client->setProtocole(SocketIO::NO_SECURE_PROTOCOLE);
$client->setProtocole(SocketIO::TLS_PROTOCOLE);
$client->setProtocole(SocketIO::SSL_PROTOCOLE);

.setPort(port)

$client->setPort(80);

.setPath(path)

$client->setPath('/socket.io/EIO=3');

.setHost(host)

$client->setPath('localhost');

About

PHP client for socket.io (websocket client)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 93.8%
  • JavaScript 6.2%