In this I would like to achieve the opposite, there are no errors, I want to generate them. I'm studying the use of PHP's ob_* functions. I found this code to understand the concepts, and it is supposed to throw an error, since I understand that once an output is sent, the headers can no longer be modified, or set the sessions or cookies. Can someone explain to me why everything flows smoothly?
<?php
//ob_start();
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
?>
<html>
<head>
<title>Página procesada con buffer de salida</title>
</head>
<body>
Esta es mi página!!!
</body>
</html>
<?php
setcookie("nombre", "john");
//ob_end_flush();
?>
Surely in your server you have activated a buffer or output control ; the behavior can be modified at
php.ini
or at runtime, depending on the characteristics of the server; remember that shared servers rarely allow these changes.There are two important variables:
off
and, when set toon
, all output is immediately sent to the browser (or stdout).Edit the file
php.ini
corresponding to your version of PHP (and restart the server) or set at runtime with ini_set('variable', 'new value'); , settingoutput_buffering
to zero andimplicit_flush
toon
.In theory, this should send any output immediately and your script should show errors, of course, as long as you have that option enabled as well; otherwise, check the documentation to configure the errors you want to show.
Important remark:
It's a very good idea to do these tests for debugging purposes, but remember to return to the original values when your project is in production, otherwise there may be performance issues.