close

Description:

void Connection::close(mixed $data = '')

Safely close the connection.

Calling close will wait for the data in the send buffer to be sent before closing the connection and will trigger the connection's onClose callback.

Parameters

$data

Optional parameter, the data to be sent (if a specific protocol is specified, it will automatically call the protocol's encode method to package the $data), and the connection will close after the data has been sent, followed by the triggering of the onClose callback.

Example

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

$worker = new Worker('websocket://0.0.0.0:8484');
$worker->onMessage = function(TcpConnection $connection, $data)
{
    $connection->close("hello\n");
};
// Run worker
Worker::runAll();