Is PHP suitable for app instant messaging servers?
Source: Internet
Author: User
Recently, I want to write an Adroid instant messaging app, which will happen in PHP. would you like to ask if PHP is suitable for instant messaging servers? What are the advantages and disadvantages? Recently, I want to write an Adroid instant messaging app, which will happen in PHP. would you like to ask if PHP is suitable for instant messaging servers? What are the advantages and disadvantages? Reply content: swoole! No need to explain !! Some time ago, I wrote
Socket-based PHP
For iOS, the SocketRocket
The PHP listening port waits for client requests and processes the requests accordingly.
The client follows the connection-logon-Send & receive message mode.
1. when the client requests a connection, the server returns an index for the connection and the connection is successful.
2. after the client detects that the connection is successful, it sends the identity information to log on to the server. if the information is correct, the server binds the account information to the connection index and returns the logon success result.
3. when the client sends a chat message to an id account, the server saves the chat information to the database and retrieves the corresponding connection index of the receiver. If yes, the client sends the chat message, the receiver listens to this information and responds. If it is not online, push notification. At the same time, a message indicating successful sending is returned to the sender to confirm that the sending is successful.
It can be used, and the server often fails. later, the RESTful backup scheme was added .... Haha, our project is a chat module written by GatewayWorker. After you have implemented a backend of instant messaging, it is estimated that you have no desire to write an instant messaging app. it is definitely the degree of instant messaging.
The php instant messaging server can use workerman, which is a high-performance php socket server framework.
Based on workerman, there is an application framework of GatewayWorker and TCP persistent connection, which simplifies your workload.
However, it is also a foundation, and you need to implement a lot of things on your own to build a house.
For research purposes, you can write and read.
If your center is making apps, it is better to use these bass services.
For example:
Huanxin-instant messaging cloud leader
LeanCloud
All of them are provided by the instant messaging service. you can use the SDK debugging method and concentrate on your own business.
These service providers all have free versions. if there are few users, there is basically no charge. According to my use of php, I feel that the polling problem is not big, and database operations will be a bottleneck. I did not do it but thought it was. I have been using a third-party wild dog. Required workerman GatewayWorker
Supports multi-protocol, distributed deployment, and hot update
The example document is very full. if you want to ask if you can, the answer is yes. The actual project combination is not suitable for comparison. it depends on the project resources, the selection of the team, and the leadership mood. If you ask this question, you must have done research such as java and have a general understanding of their respective advantages.
Based on my experience, my answer is worth trying to use php! You write it yourself, and you are familiar with it. why not open the notebook. Php cannot push messages actively.
The client requires round-robin requests to check whether new messages are sent to the server and then the server responds to the requests. Therefore, the application needs to make a regular request to the server for a long time. The cost is too high, and the new message is not timely.
You can use a general java socket to send a udp packet. the native socket code is enough to specify the address, specify the port, and run a service listening port in the background. the server writes the corresponding accept port.
Nodejs has encapsulated the socket for better communication writing.
There may be some errors in my answers. if you have made these mistakes, you are welcome to say that it is appropriate. if you cannot do it, it is not appropriate. if you don't do something, I won't do it, no one else. you and I are not a visitor, but participants of the times are absolutely acceptable and reliable. Recently, I used PHP for two chat projects: APP and H5. I used workerman's chat case to rewrite it. there are many articles and cases.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service