ob_end_flush / ob_flush

ob_end_flush(): bool / ob_flush(): bool

Two flush verbs: ob_flush pushes the active user buffer one layer down (frame stays open), ob_end_flush flushes and closes that frame; flush() pushes system-level buffers toward the client.

C C23

C23
#include <stdio.h>

/* C in reverse: stdout buffers in libc; fflush(stdout) is the single push
   from your process's buffer toward the OS */
int main(void) {
    fputs("chunk-1\n", stdout);
    fputs("chunk-2\n", stdout);
    fflush(stdout);
    fputs("chunk-3\n", stdout);
    fflush(stdout);
    printf("flushed\n");
    return 0;
}
Output
chunk-1
chunk-2
chunk-3
flushed

C++ C++26

C++26
#include <iostream>

int main() {
    // C++ in reverse: "\n" keeps the buffer, std::flush (and endl) pushes;
    // the same two-layer story PHP tells with ob_flush/flush
    std::cout << "chunk-1\n";
    std::cout << "chunk-2\n" << std::flush;
    std::cout << "chunk-3" << std::endl;
    std::cout << "flushed" << std::endl;
    return 0;
}
Output
chunk-1
chunk-2
chunk-3
flushed

C# v11.0.100

v11.0.100
using System.IO;

// C# in reverse: Console.Out auto-flushes; to feel the buffer/flush split,
// wrap a StreamWriter with AutoFlush=false and Flush by hand
using var out1 = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
out1.WriteLine("chunk-1");
out1.WriteLine("chunk-2");
out1.Flush();
out1.WriteLine("chunk-3");
out1.Flush();
Console.Out.WriteLine("flushed");
Output
chunk-1
chunk-2
chunk-3
flushed

Go v1.27.4

v1.27.4
package main

import (
	"bufio"
	"fmt"
	"os"
)

// Go in reverse: wrap stdout in bufio.Writer to gain a buffer; Flush is
// the single explicit push from your buffer to the real stdout
func main() {
	w := bufio.NewWriter(os.Stdout)
	fmt.Fprintln(w, "chunk-1")
	fmt.Fprintln(w, "chunk-2")
	w.Flush()
	fmt.Fprintln(w, "chunk-3")
	w.Flush()
	fmt.Println("flushed")
}
Output
chunk-1
chunk-2
chunk-3
flushed

Java v27.0.1

v27.0.1
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class Main {
    public static void main(String[] args) throws IOException {
        // Java in reverse: System.out is auto-flush, but a BufferedWriter
        // gains you a buffer - flush() is the explicit push
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        out.write("chunk-1\n");
        out.write("chunk-2\n");
        out.flush();
        out.write("chunk-3\n");
        out.flush(); // never close System.out - the trailing println needs it
        System.out.println("flushed");
    }
}
Output
chunk-1
chunk-2
chunk-3
flushed

JavaScript v26.13.1

v26.13.1
// JS in reverse: process.stdout is a writable stream - the runtime drains
// it for you; there is no user/system buffer split to manage by hand
process.stdout.write("chunk-1\n");
process.stdout.write("chunk-2\n");
process.stdout.write("chunk-3\n");
console.log("drained by the runtime");
Output
chunk-1
chunk-2
chunk-3
drained by the runtime

PHP v8.6.0

v8.6.0
// Two layers, two verbs: ob_flush pushes the ACTIVE USER buffer's content
// one layer down (frame stays open); ob_end_flush flushes AND closes the
// frame; flush() moves the system-level write buffer toward the client
$base = ob_get_level();
ob_start();                       // user frame A
echo "frame A\n";
ob_start();                       // user frame B
echo "frame B\n";
ob_flush();                       // drain B into A; B stays on
$stillOpen = ob_get_level() - $base;
echo "written after ob_flush\n";  // lands in B again
ob_end_flush();                   // flush B into A and close it
$afterClose = ob_get_level() - $base;
$collected = ob_get_clean();      // A holds B's two pushes plus its own line
flush();                          // system layer push (honest CLI no-op)
$backToBase = ob_get_level() === $base ? "yes" : "no";
echo "after ob_flush: +$stillOpen, after ob_end_flush: +$afterClose\n";
echo "frame A collected: [", str_replace("\n", " | ", trim($collected)), "]\n";
echo "back to baseline: $backToBase\n";
Output
after ob_flush: +2, after ob_end_flush: +1
frame A collected: [frame A | frame B | written after ob_flush]
back to baseline: yes

Python v3.15.2

v3.15.2
# Python in reverse: stdout buffers and flushes on demand; flush=True
# (or sys.stdout.flush()) is the single push verb there is
import sys

print("chunk-1", flush=True)
sys.stdout.write("chunk-2\n")
sys.stdout.flush()
sys.stdout.write("chunk-3\n")
print("flushed")
Output
chunk-1
chunk-2
chunk-3
flushed

Rust v1.99.1

v1.99.1
// Rust in reverse: stdout is line-buffered to terminals; lock it and
// flush() is the explicit push from Rust's buffer to the OS
use std::io::{self, Write};

fn main() {
    let stdout = io::stdout();
    let mut lock = stdout.lock();
    writeln!(lock, "chunk-1").unwrap();
    writeln!(lock, "chunk-2").unwrap();
    lock.flush().unwrap();
    writeln!(lock, "chunk-3").unwrap();
    lock.flush().unwrap();
    println!("flushed");
}
Output
chunk-1
chunk-2
chunk-3
flushed

TypeScript v26.13.1

v26.13.1
// TS in reverse: the stdout stream's write is typed (chunk) => boolean;
// draining stays the runtime's job
const out = process.stdout;
out.write("chunk-1\n");
out.write("chunk-2\n");
out.write("chunk-3\n");
console.log("drained by the runtime");
Output
chunk-1
chunk-2
chunk-3
drained by the runtime

Language differences

C: libc buffers stdout; fflush(stdout) is the only push verb (shown); full vs line buffering is decided by libc based on whether stdout is a terminal.

C++: "\n" does not flush; std::flush/std::endl do (shown) - the same buffer-layer + push-layer story; std::cout << std::unitbuf switches to flush-per-operation for tests.

C#: Console.Out auto-flushes by default; to feel the buffer/flush split yourself, wrap a StreamWriter (AutoFlush=false + Flush, shown).

Go: stdout is unbuffered by default (straight to the fd); wrap bufio.Writer to gain a buffer, Flush is the explicit push (shown) - one user layer fewer than PHP, same two-stage shape.

Java: System.out is an auto-flush PrintStream; BufferedWriter + flush() gives explicit control (shown).

JavaScript: process.stdout is a writable stream the runtime drains for you (shown); there is no user/system buffer split - write's return value only signals backpressure.

PHP: three layers, three verbs: ob_flush pushes the ACTIVE USER buffer one layer down (the frame stays open); ob_end_flush pushes it down and closes that frame; flush() pushes the system-level write buffers (PHP + CGI/web server) toward the client. Together with the flush entry (A20) they make the complete picture. Under CLI flush is an honest no-op (the example says so); default ob_* flags allow flushing - the PHP_OUTPUT_HANDLER_FINAL/FLUSHABLE details are in the manual.

Python: print's flush=True or sys.stdout.flush() (shown) - one buffer, one push verb; python -u and PYTHONUNBUFFERED are the global switches.

Rust: io::stdout() ships a LineWriter (line-buffered to terminals), flush() is the explicit push (shown); block buffering means wrapping BufWriter yourself.

TypeScript: same as JS - the runtime manages the stream (shown); TS contributes the write signature ((chunk: string) => boolean).