通过PHP浏览器之间的通信 [英] Communication between browsers via PHP

查看:121
本文介绍了通过PHP浏览器之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个简单的ajax聊天客户端的一个学校项目,并认为可以通过某种方式来实现这一点,但它似乎IMO是的非常的繁琐方式:

I am building a simple ajax chat client for a school project and have thought of a way to implement this, but it seems IMO to be very cumbersome approach:

1)用户A发送它是由服务器端的PHP脚本接受并保存到数据库中的信息 2)用户B的浏览器周期性地启动一个服务器端的PHP脚本来检查是否有在数据库中,用户B的PHP脚本的任何消息认为,从用户A的消息,并返回它们。

1) User A sends message which is accepted by a server-side PHP script and saved to database 2) The browser of User B periodically launches a server side PHP script to check if there are any messages in the database for User B. PHP script finds messages from User A and returns them.

这是正确的做法?可以在这两个用户之间的通信可以不使用数据库来实现?

Is this the right approach? Can communication between these two users be achieved without a database?

(这是我的第一个Web应用程序......如果我做这一点没有浏览器+ HTTP,我只想让与侦听TCP套接字持久化类的Java程序,并转发信息到相应的地址)

(This is my first web-application...if I was making this without browsers + HTTP, I would just make a Java program with persistent class that listened on TCP sockets, and forwarded messages to the appropriate address)

推荐答案

是您的解决方案是启动不够好。你在做什么是轮询服务器是否有针对特定用户的所有聊天信息。好就好了。

Yes your solution is good enough for starting. What you are doing is polling the server if there are any chat messages for a particular user. Good enough.

但是,如果你想后藤新的水平,(可能会​​是艰难的),你可以拥有它可以推新邮件到客户端浏览器的服务器。这就是所谓的彗星。但是,这需要大量的服务器资源(如果你的用户群将会超过数以千计)。

But if you wanna goto the next level, (probably could be tough), you can have a server which can push new messages onto client browsers. This is called "Comet". But it will need extensive server resources (if your userbase is going to exceed to thousands).

先试试你的方法,去这下。

Try your method first and go for this next.

这篇关于通过PHP浏览器之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆