search
HomePHP FrameworkWorkermanSeveral issues that worker developers must know

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!

Statement
This article is reproduced at:workerman. If there is any infringement, please contact admin@php.cn delete

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 Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.