Method
ClientRequest::flush
Commit the head (an implicit 200) and put it on the wire, with nothing buffered.
Description#
public ClientRequest::flush(): voidExamples#
use Swerve\ClientRequest;
use Swerve\RequestHandler;
$app = new RequestHandler(function (ClientRequest $request) {
$request->sendResponseHeaders(200, ['content-type' => 'text/plain']);
$request->flush(); // the client sees the head now, before any work is done
foreach (['parsing', 'indexing', 'done'] as $step) {
phasync::sleep(0.05); // the work
$request->write("$step\n"); // each write is a chunk on the wire
}
});
if (debug_backtrace()) {
return $app; // swerve loads this file: it is the application's swerve.php
}
// Run directly: serve the application with swerve, and send it requests
require __DIR__ . '/../serve.php';
serve(__FILE__, ["GET /rebuild HTTP/1.1\r\nHost: example\r\n\r\n"]);Output
HTTP/1.1 200 OK content-type: text/plain Server: Swerve Transfer-Encoding: chunked Connection: close 8 parsing 9 indexing 5 done 0