Skip to content

PHP client for socket.io (websocket client)

Notifications You must be signed in to change notification settings

SpottedInc/php-socket-io-event-emitter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Socket Client

Forked from : https://github.com/touskar/php-socket-io-event-emitter.

It seems that the original project (above) has not been maintained from a long time (about 2 years).

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");
}

NodeJS

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));
  });
});

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%