简体   繁体   中英

CakePHP and socket

Using CakePHP, I want to establish a bidirectional connection between server (CakePHP) and client (Browser) for realtime exchange of data (eg for a chat).

Therefore I dont want to have the page reloaded every single time I am firing a message.

In my understanding this is either working with AJAX, which is not recommended for chatting, or via a WebSocket.

However, I cannot find out how to establish such a connection. One chapter in the CakePHP documentation mentions HTTPClients which unfortunately seems not to be what I want to have.

However, I found this Socketbased Library called Ratchet: http://socketo.me/docs/flow Did someone ever tried to establish anything similar? I would not even know how to integrate this Socket into my CakePHP project.

Your question has all the answers. Either long polling or websockets. You could use ratchet or reactPHP . To include it in cakePHP you might want to use a plugin like this .

I've had success on building a stand-alone real time app with php thruway, although I haven't tried with cakePHP. Regardless, thruway can be installed via composer so it should go respective vendor folder inside your cakePHP's root folder then it could be namespaced and perhaps call the Client.php from a controller's action, etc... thruway's router must be running(prior) as a separate execution.

( https://github.com/voryx/Thruway )

Also check AutobahnJS as it follows pub/sub patterns same as thruway's.

good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM