Home > PHP Framework > Workerman > body text

Several issues that worker developers must know

Release: 2019-11-26 18:11:50
forward
5143 people have browsed it

The following tutorial column of workerman will introduce to you several issues that workerman developers must know. I hope it will be helpful to friends in need!

Several issues that worker developers must know

1. Workerman does not rely on apache or nginx

workerman itself is already a container similar to apache/nginx. As long as the PHP environment is OK, workerman can run.

2. Workerman is started from the command line.

The startup method is similar to apache using the command (workerman cannot be used in general web spaces). The startup interface is similar to the following

Several issues that worker developers must know

3. A heartbeat must be added for a long connection

A heartbeat must be added for a long connection. A heartbeat must be added for a long connection. Long connections must add heartbeats, and say important things three times.

Long connections without communication for a long time will definitely be killed by the firewall and disconnected. The long-term connection application without heartbeat is just waiting for the boss to KO you.

4. The client and server protocols must correspond to communicate.

This is a very common problem among developers. For example, if the client uses the websocket protocol, the server must also use the websocket protocol (server new Worker('websocket://0.0.0.0...')) to be able to connect and communicate.

Do not try to access the websocket protocol port in the browser address bar, and do not try to use the websocket protocol to access the bare tcp protocol port. The protocol must correspond.

The principle here is similar to that if you want to communicate with British people, then use English. If you want to communicate with Japanese people, use Japanese. The language here is similar to the communication agreement. Both parties (client and server) must use the same language to communicate, otherwise communication will not be possible.

5. Possible reasons for connection failure

A very common problem when you first start using Workerman is that the client fails to connect to the server. The reasons are generally as follows:

1. The server firewall (including the cloud server security group) blocks the connection (50% probability is this)

2. The protocols used by the client and the server are inconsistent (30 % chance)

3. The IP or port is written wrong (15% chance)

4. The server is not started

6. Do not use exit die sleep statement

Business execution of the exit die statement will cause the process to exit and display the WORKER EXIT UNEXPECTED error. Of course, when the process exits, a new process will be restarted immediately to continue the service. If you need to return, you can call return. The sleep statement will cause the process to sleep. No business will be performed during the sleep process, and the framework will also stop running, resulting in all client requests of the process being unable to be processed.

7. Do not have an infinite loop in the business code

Do not have an infinite loop in the business code, otherwise the control will not be returned to the worker framework, resulting in the inability to receive processing Other client messages.

8. Restart Workerman when changing the code

Workerman is a memory-resident framework. When changing the code, you need to restart Workerman to see the effect of the new code.

9. It is recommended to use the GatewayWorker framework for long-term connection applications

Many developers use workererman to develop long-term connection applications, such as instant messaging, Internet of Things, etc., long-term connection applications It is recommended to use the GatewayWorker framework directly, which is specially encapsulated on the basis of workerman to make it simpler and easier to use as a long-connection application backend.

10. Support higher concurrency

If the number of concurrent business connections exceeds 1,000 and is online at the same time, be sure to optimize the Linux kernel and install the event extension or libevent extension.

For more workerman tutorials, please pay attention to the workerman tutorial column.

The above is the detailed content of Several issues that worker developers must know. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:workerman
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!