Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Http\Response->write(string $data): bool
Data to write to the HTTP body. The max length of the data by default is 2M. Controlled by buffer_output_size
If successful, true
is returned otherwise false
Send data back to the HTTP client in a segmented chunk, the write()
method uses HTTP Chunk to send content back to the browser. This feature uses Transfer-Encoding
to transfer segmented messages or payload body data between a client and server, data can be sent in a series of chunks.
If you have already performed calls to write()
and then call $response->end()
afterwards, it will send a chunk of length 0 to end data transmission with the client.
This method must be called before the
$response->end()
method.
Since v4.10.0, you can use this method to send HTTP2 DATA frame or push data to clients.
If you want to send a complete HTTP body back to the client all at once, the $response->end
method might be more useful.
Adjust max data size by changing buffer_output_size
, the default is 2M