What are some common pitfalls or misunderstandings when using flush() in PHP?
One common pitfall when using flush() in PHP is not understanding that it only flushes the output buffer to the client's browser, but does not guarantee that the data is actually sent immediately. To ensure that the data is sent immediately, you can use ob_flush() in combination with flush(). Additionally, make sure to set the appropriate headers to prevent browser caching.
ob_start();
echo "Hello, world!";
ob_flush();
flush();
header('Content-Length: ' . ob_get_length());
header('Connection: close');
ob_end_flush();