简体   繁体   English

用PHP实时功能

[英]Real Time Functionlity with php

I am working on attendance system where project management system is also handling using Javascript\\Jquery at client side and PHP\\MySQL at server side. 我正在使用考勤系统,其中项目管理系统也在客户端使用Javascript \\ Jquery和在服务器端使用PHP \\ MySQL进行处理。

A feature in my web app is user message to admin. 我的Web应用程序中的一个功能是向管理员发送用户消息。 For this I have applied an ajax request which is made by setTimeout function (after every 15 seconds) to check that is there any new message comes in database if yes then return it to the admin. 为此,我应用了一个由setTimeout函数发出的ajax请求(每15秒之后),以检查是否有新消息进入数据库(如果是),然后将其返回给管理员。

It working fine but the drawback is (as you know) continuous request to server which really poor and bad. 它工作正常,但缺点是(如您所知) 对服务器的连续请求,这确实很糟糕。 As I know that real time functionality can solve this problem I have checked some link websocket.io and signlR but there are applicable with Nodejs and asp.net. 据我所知,实时功能可以解决此问题,我已经检查了一些链接websocket.io和signlR,但它们适用于Nodejs和asp.net。 So, how can I apply real time functionality with php or I get that new data have reached in to database without continues request with ajax. 因此,如何在php中应用实时功能,或者在不继续使用ajax的情况下获得新数据已到达数据库的信息。

There are actually some PHP tools for doing this now. 实际上,现在有一些PHP工具可以执行此操作。 For instance, check out Ratchet . 例如,查看Ratchet

It's also possible to do bi-directional sockets by creating a simple TCP/IP server. 通过创建简单的TCP / IP服务器,也可以进行双向套接字。 I've done this before for bi-directional communication between a PHP server and a desktop app. 之前,我已经在PHP服务器和桌面应用程序之间进行双向通信。

http://php.net/manual/en/sockets.examples.php http://php.net/manual/en/sockets.examples.php

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

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