In swoole, you can use Server->bind to get the uid. Server->bind will bind the connection to a user-defined UID. You can set dispatch_mode=5 Set this value for hash fixed allocation. It can be guaranteed that all connections of a certain UID will be assigned to the same Worker process.
function Server->bind(int $fd, int $uid);
$fd: Connection ID
$uid: UID to be bound, must be a non-0 number
When the UID is not bound, fd modulo is used by default Allocation
The same connection can only be bound once. If the UID has been bound, calling bind again will return false
You can use $serv->getClientInfo($fd) to view the connection The value of the bound UID
is only valid when dispatch_mode=5 is set
Under the default dispatch_mode=2 setting, the Server will allocate connection data to different Worker processes according to socket fd. Because fd is unstable, if a client is disconnected and reconnected, fd will change.
In this way, the client's data will be distributed to other Workers. After using bind, you can assign it according to the user-defined UID. Even if the connection is disconnected and reconnected, TCP connection data with the same UID will be assigned to the same Worker process.
Recommended learning: swoole video tutorial
The above is the detailed content of How to get uid in swoole. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

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),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools
