Hello! Where ob_flush() contents of the ob_flush() output buffer ob_flush() ? In the browser in this case?
If at the end of the code do not put ob_flush(); , the string is still output. Or php puts it yourself? ..

 ob_start(); // включить буфер echo 'Test'; // это echo попадает в буфер (задерживается) setcookie("name", "John"); // установить (отправить) куки echo $_COOKIE['name']; // => John ob_flush(); // Сброс (отправка) буфера вывода 
  • one
    in normal life, these functions are usually not used. The contents of the buffer is transferred to the http-server, which adds it to the response and sends it to the client. In the normal execution of the script after it is executed, the server also sends the result. The usefulness of using the buffer is that it can be cleared, and not to send already output data. - teran
  • The buffer is used to simplify the code. You can display the page header and only then proceed to the processing of parameters. If, as a result, you want to make a redirect, you will not be able to do this, since the redirect is done via the HTTP response header, and you already have some content displayed. To get around this situation, a buffer is applied. All output is added to the memory area, and at the end of the script, if everything is normal, its contents are output to the output stream, that is, in fact, transferred to the HTTP client. - Mark Shevchenko
  • Thanks for the explanation. - Alexander Zharichenko
  • @AlexanderZharichenko in order to understand why I edited your post, including removed from there "hello" , which you returned, read this - teran

1 answer 1

The buffer is forcibly cleared at the end of the request, if the ob_flush function or analogues have not been called previously. You can prevent output by using appropriate functions (for example ob_end_clean )