一个PHP写成的Socket.IO客户端,可以方便快捷的集成到你的项目里
系统需求:
Socket.IO 0.8+
PHP 5.3+
NodeJS 0.6.5+
用法:
Socket.IO端
var io = require('socket.io').listen(8000); io.sockets.on('connection', function (socket) { console.log('user connected!'); socket.on('foo', function (data) { console.log('here we are in action event and data is: ' + data); }); });
PHP端
use ElephantIO\Client as Elephant; $elephant = new Elephant('http://localhost:8000', 'socket.io', 1, false, true, true); $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`';