Stooney Posted October 6, 2008 Share Posted October 6, 2008 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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 I always use a templating system or views in the case of an MVC set-up, so that this problem is never really encountered. You shouldn't output ANYTHING in your business logic, and hand off everything to the view for display. Quote Link to comment Share on other sites More sharing options...
corbin Posted October 7, 2008 Share Posted October 7, 2008 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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 7, 2008 Share Posted October 7, 2008 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. Quote Link to comment Share on other sites More sharing options...
Stooney Posted October 7, 2008 Author Share Posted October 7, 2008 Corbin I'm aware of that. I was just using a quick example. Quote Link to comment Share on other sites More sharing options...
corbin Posted October 8, 2008 Share Posted October 8, 2008 Eh just making sure since I see people use incomplete URLs in headers all the time, and it annoys the hell outta me. Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted October 8, 2008 Share Posted October 8, 2008 I am pretty sure that the performance hit comes from ob_end_flush(); and if you don't call that the result is the same(as in the page is still rendered correctly) without the performance hit. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.