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

How to get uid in swoole

尚
Original
2019-12-13 16:56:514756browse

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

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

Statement:
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
Previous article:How to keep swoole onNext article:How to keep swoole on