简体   繁体   English

CakePHP和套接字

[英]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). 使用CakePHP,我想在服务器(CakePHP)和客户端(浏览器)之间建立双向连接,以实时交换数据(例如聊天)。

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. 根据我的理解,这要么是使用AJAX,不建议用于聊天,要么是通过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. CakePHP文档中的一章提到了HTTPClients,遗憾的是它似乎不是我想要的。

However, I found this Socketbased Library called Ratchet: http://socketo.me/docs/flow Did someone ever tried to establish anything similar? 但是,我发现这个名为Ratchet的Socketbased库: http ://socketo.me/docs/flow是否有人试图建立类似的东西? I would not even know how to integrate this Socket into my CakePHP project. 我甚至不知道如何将这个Socket集成到我的CakePHP项目中。

Your question has all the answers. 你的问题有所有的答案。 Either long polling or websockets. 长轮询或websockets。 You could use ratchet or reactPHP . 你可以使用棘轮reactPHP To include it in cakePHP you might want to use a plugin like this . 将其包含在CakePHP你可能想使用插件像这样

I've had success on building a stand-alone real time app with php thruway, although I haven't tried with cakePHP. 虽然我没有尝试过使用cakePHP,但我已经成功构建了一个独立的PHP实时应用程序。 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. 无论如何,可以通过composer安装thruway,因此它应该在cakePHP的根文件夹中找到各自的vendor文件夹,然后它可以是命名空间,也可以从控制器的操作等调用Client.php ... thruway的路由器必须运行(之前)as单独执行。

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

Also check AutobahnJS as it follows pub/sub patterns same as thruway's. 同时检查AutobahnJS,因为它遵循与thruway相同的pub / sub模式。

good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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