Swoole Server confirm()

4.x is outdated, please check the latest version 22.x

Latest version: pecl install openswoole-22.1.2


<?php Swoole\Server->confirm(int $fd): bool



The file descriptor ID of the client that you want to confirm the connection for. You can get the fd from the onConnect callback event.



If successful, true is returned, otherwise false for when the client connection does not exist or is already in a monitoring state.


Confirm a client connection and use it in conjunction with enable_delay_receive server configuration option.

When the client establishes a connection, do not listen for readable events (or data), only trigger the onConnect event callback when the client connects and proceed to confirm their connection, once the connection is confirmed then the server will listen for readable event data that is received from client connection, allowing the server to accept client data.

This method is generally used to protect servers and avoid traffic overload attacks. The onConnect function is triggered when a client connection is received , which can determine the source IP and whether it is allowed to send data to the server. You can delay the client before their connection is added to the event loop.

Available since v4.5.0


// Create a new Server object and listen on port
$server = new Swoole\Server("", 9501);

    'enable_delay_receive' => true,

// Listen for connection entry events
$server->on('Connect', function ($serv, $fd)
    // Check the client $fd here and then confirm if there is no problem

// Only process client data when the connection has been confirmed
$server->on('Receive', function ($serv, $fd, $reactor_id, $data)
    $serv->send($fd, "Server: ".$data);

// Listen for connection close events
$server->on('Close', function ($serv, $fd)
    echo "Client: Close.\n";

// Start the server
Last updated on August 31, 2022