All the sample code I find for socket.io seems to be for node.js on the VPS side, so no help there.
Bạn đang xem: Socket io với php
It may be a little late for this question to lớn be answered, but here is what I found.
I don"t want to debate on the fact that nodes does that better than php or not, this is not the point.
The solution is : I haven"t found any implementation of socket.io for PHP.
Xem thêm: Nghĩa Của Từ Zygodactyl Là Gì Trong Tiếng Việt? 10 Bí Mật Thú Vị Về Loài Chim Gõ Kiến
But there are some ways lớn implement WebSockets. There is this jQuery plugin allowing you lớn use Websockets while gracefully degrading for non-supporting browsers. On the PHP side, there is this class which seems khổng lồ be the most widely used for PHPhường WS servers.
answered Nov 18 "11 at 8:25
Florian MargaineFlorian Margaine
50.9k1414 gold badges8787 silver badges110110 bronze badges
Add a phản hồi |
If you want to use socket.io together with php this may be your answer!
they are also on github:
Elephant.io provides a socket.io client fully written in PHP that should be usable everywhere in your project.
example from the project website (communicate with websocket VPS through php)
use ElephantIOClient 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();emang lại "tryin khổng lồ sover `bar` khổng lồ the sự kiện `foo`";socket io server
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); ););