PHP套接字是进行基于PHP jQuery的聊天的可行选择吗? [英] Is PHP socket a viable option for making PHP jQuery based chat?

查看:50
本文介绍了PHP套接字是进行基于PHP jQuery的聊天的可行选择吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为drupal开发一个聊天模块.我计划为聊天消息处理提供多个后端.我最初是从AJAX开始的,现在已经包含了长轮询技术.然后我遇到了ape(ajax推送引擎),它看起来很有前途.但这需要在服务器端安装ape才能使聊天模块正常工作.尽管我还将其作为聊天的后端之一,但我的主要重点是找到一种解决方案,该解决方案可以处理可接受数量的同时聊天连接,而无需进行任何服务器端修改,从而使人们可以轻松使用它.

I am developing a chat module for drupal. I plan to provide multiple backends for chat message processing. I initially started with AJAX and have now included long polling technique in it. Then I came across ape(ajax push engine) and it looks promising. But it will require server side installation of ape for the chat module to work. Although I will also include this as one of the backends for the chat, my main focus is to find a solution which can handle acceptable number of simultaneous chat connections WITHOUT making any server side modifications so that people can use it easily.

我在网上冲浪,偶然发现PHP Socket编程,这似乎是一个可行的选择.

I was surfing on net and came across PHP Socket programming and it looks like a viable option.

  • 如果我编写了一个基于php的聊天服务器,是否能够仅使用jQuery(以及ActionScript)就能维持一个可以双向发送数据(从服务器到客户端,反之亦然)的连接?显然,我不会在客户端使用AJAX.
  • 如果我编写一个基于php套接字的高效聊天脚本并说要给它分配50MB的RAM,服务器还能同时处理多少个连接?
  • 共享托管的人是否可以运行基于php的服务器端代码,因为他们没有外壳访问权限,就像我们可以选择运行cron一样?
  • 我还读过某处php不是多线程语言,因此您根本不应该使用套接字.这是真的吗?
  • 是否可以使用其他方法,并且在不进行任何服务器端修改的情况下,其效率会更高?

推荐答案

您应考虑的问题:每个新连接都将阻止PHP进程.因此,如果您在某处建立了套接字连接,并使其长时间打开,则PHP进程将被阻止,它将无法接受其他连接.因此,如果您有50个PHP进程,则一次可以建立50个连接.

What you should think about: Every new connection will block a PHP process. So, if you establish a socket connection to somewhere and let it open for long time the PHP process will be blocked, it cannot accept another connection. So, if you had 50 PHP processes, 50 connections may be established at one time.

这就是为什么我个人更喜欢在诸如聊天之类的彗星应用程序中使用Node.JS ...

This is why I personally prefer using Node.JS for comet applications like chat...

这篇关于PHP套接字是进行基于PHP jQuery的聊天的可行选择吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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