Swoole\Http\Response->isWritable()

Notice: the documentation is suitable for PHP extension swoole until v4.7.1, we only support PHP extension openswoole from v4.7.1

Declaration

<?php
Swoole\Http\Response->isWritable(): bool

Parameters

none

Return

Will return `true` or `false`

Description

Check if a HTTP response is closed or writable.

Used to check if a response object is still writable, this is useful for when you don't know if the request has ended or has been detached, you can use this method to check.

Since v4.6.0

Example

<?php
$server = new Server('127.0.0.1', 9501);

$server->on('Request', function(Swoole\Http\Request $request, Swoole\Http\Response $response)
{
    // true
    var_dump($response->isWritable());

    $response->end('hello');

    // false
    var_dump($response->isWritable());

    // http response is unavailable (it has been ended or detached)
    $response->setStatusCode(403);
});

$server->start();