OpenSwoole\Http\Response->end()

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

Declaration

<?php OpenSwoole\Http\Response->end(string $data): bool

Parameters

data

The data to send back to the client, the HTTP body

Return

bool

If successful, true is returned otherwise false

Description

Sends back data to the client, data is send to the HTTP body and then the request is terminated after the response has finished sending. You can only ever call this method once.

If the client enables keepalive, the connection between the server and the client will maintained but if the client doesn't enable keepalive, the connection between the server and the client will be closed.

Example

<?php
OpenSwoole\Http\Response->end(string $data);

$server->on('Request', function(OpenSwoole\Server\Request $request, OpenSwoole\Server\Response $response)
{
  // Send
  $response->end('<h1>Hello World!</h1> <br/> <p>from OpenSwoole.</p>');
});

Notes

  • If you need to send dta to the client multiple times or chunk data, use the server $response->write method instead

  • By default both the ->end() and ->write() methods only support sending data up to 2M, this can be increased by adjusting the buffer_output_size

  • If you exceed the set buffer_output_size, you will receive the following error:

WARNING finish (ERRNO 1203): The length of data [262144] exceeds the output buffer size[131072], please use the sendfile, chunked transfer mode or adjust the output_buffer_size
Last updated on September 20, 2022