A route handler that returns a \Generator streams every yield chunk to the browser the moment it produces it — the page renders progressively instead of waiting for the whole HTML to assemble. Click Run below; the chunks arrive in the dark panel.
$app->route('/stream/ssr', function () {
return (function () {
yield '<section><h2>Loading…</h2></section>';
foreach (slow_data_source() as $row) {
yield "<article>{$row}</article>";
}
yield '<footer>Done.</footer>';
})();
});