OpenSwoole\Http\Response->isWritable()

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\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(OpenSwoole\Http\Request $request, OpenSwoole\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 September 1, 2022