Home > PHP Framework > Swoole > How to get uid in swoole

How to get uid in swoole

Release: 2019-12-13 16:56:51
Original
4775 people have browsed it

How to get uid in swoole

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);
Copy after login

$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!

Related labels:
source:php.cn
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