id

Description:

int Connection::$id

The id of the connection. This is an auto-incrementing integer.

Note: Workerman is multi-process, and each process maintains its own auto-incrementing connection id, so connection ids may be duplicated between multiple processes. If you want non-duplicated connection ids, you can reassign connection->id as needed, for example, by adding a worker->id prefix.

See Also

Worker's connections property

Example

use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';

$worker = new Worker('tcp://0.0.0.0:8484');
$worker->onConnect = function(TcpConnection $connection)
{
    echo $connection->id;
};
// Run the worker
Worker::runAll();