Table of Contents
回复内容:
Home Backend Development PHP Tutorial PHP适合做app即时通讯的服务端吗?

PHP适合做app即时通讯的服务端吗?

Jun 17, 2016 am 08:31 AM
app php

最近想写一个Adroid版的即时通讯app,刚好对PHP也会一些,想问下大家PHP适合做即时通讯的服务端吗?有什么优劣之处吗?

回复内容:

swoole!不用解释!! 前段时间裸写了一个
PHP部分基于Socket
iOS部分是用的SocketRocket
主要就是PHP监听端口等待客户端请求,并对请求做出相应的处理
客户端则按照连接-登录-发送&接收消息的模式来
1、客户端请求连接,服务端给予该连接一个index,返回连接成功
2、客户端检测到连接成功后,发送身份信息到服务端登录,若是信息正确,服务端将该账号信息与连接index绑定,返回登录成功
3、客户端对某一id账号发送聊天信息,服务端将该聊天信息保存到数据库,同时检索该接收方是否有与之对应的连接index,有则发送聊天信息,接收方会监听到该信息并响应。如果不在线则push notification。同时也会返回发送成功的信息给发送方,以便确认发送成功。
用是能用,服务端经常挂掉,后来还是加RESTful后备方案。。。。 哈哈,我们项目上就是用的GatewayWorker写的聊天模块。 等你实现了一个即时通讯的后端后,估计你也没欲望写即时通讯的app了,绝对是看见就吐的程度。

php即时通讯服务端可以采用workerman,是一个高性能的php socket服务器框架。

在workerman 的基础上又有GatewayWorker,TCP长连接的应用框架,简化你的工作量。

不过也就是个地基,还要你自己实现一大堆东西来建房子。

如果是为了研究的话,可以写写看。

如果你的中心是做出app来,还不如用这些bass服务。

例如:
环信-即时通讯云领导者
LeanCloud
都有即时通讯服务提供,接入SDK调调方法就可以了,专心于自己的业务。

这些服务商都是有免费版本的,用户少的话基本上不用收费。 以我用php的情况来看,感觉轮询问题不大,数据库操作会是瓶颈,我没做过只是觉得。我用第三方野狗做过感觉 还可以。 必须workerman的GatewayWorker
支持多协议、分布式部署、热更新
例子文档非常全 如果你要问能不能,答案是能。实际项目中合不合适要对比,要看项目资源,要看团队的选型,还要看领导的心情。你这么问,想必你肯定做过调研比如java,对它们各自的优势有大致了解。
根据的经验,我的答案是值得尝试使用php!反正是你自己写,也熟悉的,何不放开撸。 php在消息主动推送那里应该不行
需要客户端轮训询请求 检测是否有新的消息 请求服务器端 然后服务器端响应 因此app需要定时请求服务器 时间的取舍不好做 短了代价太高 长了新消息不及时
可以用一般的java socket就可以 发送udp包 原生socket几句代码就够了 指定地址 指定端口 后台跑一个service监听端口 服务器端写好相应的接受收
nodejs 对socket已经封装了 通信更好写
我的回答可能还有一些错误 自己做过这些 不对的地方欢迎大家指正 做出来了就合适,做不出来就不合适,有些事情吧,你不去做,我不去做,就没人了,要知道,你我都不是个看客,而是时代的参与者 绝对可以,而且很靠谱。最近使用PHP做了两个聊天的项目,一个是APP,一个是H5。我用的是workerman的chat案例改写的,文档很充分,案例也比较多。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles