Swoole\Http\Response->isWritable()

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


Latest version: pecl install openswoole-22.1.2

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();
Last updated on August 31, 2022