Socket io với php

Is it possible khổng lồ use on the client side và communicate with a PHP. based application on the server? Does PHP. even support such a "long-lived connection" way of writing code?

All the sample code I find for 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 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 together with php this may be your answer!

they are also on github: provides a client fully written in PHP that should be usable everywhere in your project.

Xem thêm: Property Là Gì Js - Tại Sao Prototype Lại Quan Trọng Trong Javascript

It is a light and easy to use library that aims khổng lồ bring some real-time functionality lớn a PHPhường application through & websockets for actions that could not be done in full javascript.

example from the project website (communicate with websocket VPS through php)

php server

use ElephantIOClient as Elephant;$elephant = new Elephant("http://localhost:8000", "", 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("").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); ););

Chuyên mục: