ob_implicit_flush
ob_implicit_flush(bool $enable = true): void
Toggles implicit flush mode; when enabled every output call flushes automatically.
C C23
#include <stdio.h>
int main(void) {
// C has no implicit-flush switch: stdout is line-buffered (terminal) / fully buffered (pipe) by default; fflush pushes manually
printf("stream: line 1\n");
fflush(stdout);
printf("stream: line 2\n");
printf("done\n");
return 0;
}
stream: line 1 stream: line 2 done
C++ C++26
#include <iostream>
int main() {
// std::endl = newline + flush (flush-on-write); "\n" does not flush
std::cout << "stream: line 1" << std::endl;
std::cout << "stream: line 2\n";
std::cout.flush();
std::cout << "done\n";
return 0;
}
stream: line 1 stream: line 2 done
C# v11.0.100
// Console.Out defaults to AutoFlush=true — PHP-style implicit flushing is always on
Console.WriteLine("stream: line 1");
Console.WriteLine("stream: line 2");
Console.WriteLine("done");
stream: line 1 stream: line 2 done
Go v1.27.4
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
// Go has no implicit-flush switch: bufio.Writer batches up; Flush is what lands on stdout
w := bufio.NewWriter(os.Stdout)
fmt.Fprintln(w, "stream: line 1")
fmt.Fprintln(w, "stream: line 2")
w.Flush()
fmt.Println("done")
}
stream: line 1 stream: line 2 done
Java v27.0.1
public class Main {
public static void main(String[] args) {
// System.out's println auto-flushes; print does not — flush manually
System.out.println("stream: line 1");
System.out.print("stream: line 2\n");
System.out.flush();
System.out.println("done");
}
}
stream: line 1 stream: line 2 done
JavaScript v26.13.1
// console.log has no flush API: Node stdout emits on write, no PHP-style batching
console.log("stream: line 1");
console.log("stream: line 2");
console.log("done");
stream: line 1 stream: line 2 done
PHP v8.6.0
// Implicit flushing on: every output call auto-flushes (no manual ob_flush needed)
ob_implicit_flush(true);
echo "stream: line 1\n";
echo "stream: line 2\n";
// Implicit flushing off: back to batching/manual control
ob_implicit_flush(false);
echo "done\n";
stream: line 1 stream: line 2 done
Python v3.15.2
import sys
# Python has no global implicit-flush switch: flush manually when block-buffered, or use print(flush=True)
sys.stdout.write("stream: line 1\n")
sys.stdout.flush()
print("stream: line 2", flush=True)
print("done")
stream: line 1 stream: line 2 done
Rust v1.99.1
use std::io::{self, Write};
fn main() {
// stdout is line-buffered (LineWriter): writing whole lines gets the implicit-flush effect; fragment output without newlines needs manual flush
print!("stream: line 1\n");
io::stdout().flush().unwrap();
println!("stream: line 2");
println!("done");
}
stream: line 1 stream: line 2 done
TypeScript v26.13.1
// console.log has no flush API: Node stdout emits on write, no PHP-style batching
console.log("stream: line 1");
console.log("stream: line 2");
console.log("done");
stream: line 1 stream: line 2 done
Language differences
C: no global switch — stdout is fully buffered when piped; setvbuf(stdout, NULL, _IONBF, 0) disables buffering (always-implicit-flush) and fflush pushes manually.
C++: the idiom is std::endl (newline + flush) for line-wise pushes; std::unitbuf makes every output auto-flush, close to PHP's implicit flush.
C#: Console.Out defaults to AutoFlush=true — implicit flush is effectively always on; batch yourself with a StreamWriter.
Go: no implicit-flush switch — writing straight to os.Stdout is immediate; bufio.Writer batches until Flush.
Java: System.out's println auto-flushes, print doesn't and needs a manual flush(); rebuild the PrintStream to customize autoFlush.
JavaScript: console.log has no flush concept; Node stdout writes as it goes (line buffered on a TTY, OS-buffered under pipes).
PHP: with ob_implicit_flush(true) every output call flushes automatically — great for live logs; it changes when output is sent, not the content itself — invisible in a captured CLI run, visible in a live stream.
Python: no global switch; use flush=True or sys.stdout.flush() when block-buffered, or -u/PYTHONUNBUFFERED=1 for unbuffered everywhere (implicit-flush equivalent).
Rust: std::io::Stdout is a LineWriter — whole lines go out immediately, i.e. line-level implicit flush; print! without a newline needs a manual flush().
TypeScript: same as JavaScript — no flush concept in console.log.