Jump to content

Design Question - Output buffering


Stooney

Recommended Posts

Are there any cons to using output buffering?  With my current design, I do ob_start() at the beginning of the site, then at the end if a variable (for simplicity i'll just say $no_output) == true then ob_end_flush() will not be called and no output will happen.  This is so that certain scripts such as logging in can do their thing then still header("Location: index.php").  I'm using mvc and mod_rewrite.

 

Example:

<?php
ob_start();
$router->delegate();  //for example, if the url was /auth/login the auth controller is called and the login action ran.  
//login sets no_output to true and does header("Location: index.php");
if(!$no_output){
    //If the requested page was something like contact, then $no_ouput would be false and ob_end_flush called.
    ob_end_flush();
}
?>

 

Another option I've considered is instead of site.com/controller/action, maybe doing site.com/request_type/controller/action.  Request type would be either page or process, where page can output stuff,  and process is only for things such as login which redirect when they're done and don't produce output.

 

Any thoughts?  I'm a newbie when it comes to this type of design so let me know if I'm trying to drive a station wagon through an ocean.

 

Link to comment
https://forums.phpfreaks.com/topic/127261-design-question-output-buffering/
Share on other sites

Output buffering can slow things down and use more memory.

 

 

The performance hit it will have is directly proportional to the size of the content being stored in the buffer.

 

 

 

Oh, by the way, if I remember correctly, header("Location: blah") calls are supposed to use full, not relative, URLs.

Output buffering can slow things down and use more memory.

 

 

The performance hit it will have is directly proportional to the size of the content being stored in the buffer.

 

 

 

Oh, by the way, if I remember correctly, header("Location: blah") calls are supposed to use full, not relative, URLs.

 

Yeah, they're better as full URL for corss-browser compliance.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.