Torrie Posted April 30, 2015 Share Posted April 30, 2015 My web-page loops through and echoes all 50,000 entries from a several-column mySQL database (part number, price, description, etc.). It is tedious for me, because It takes about a full minute for my browser to completely load it. I had an idea: Use "ob_start" at the beginning of the script, and insert an "ob_end_flush()" assertion in my "while" loop to get executed every 50 loops, like this: <?php ob_start(); ## access big mySQL database and output it to browser $i=0; while ( $a_row = mysql_fetch_assoc($result) ) { # echo output to browser if($i %50 == 0) { ob_end_flush(); } } ?> That cut the time down from 60 seconds down to about a second and a half. The problem is, the results are goofy (several mySQL rows missing, didn't get output to browser). Is there a better way? Or, am I on the right track? And, if I'm on the right track, what can I do to fix this? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/ Share on other sites More sharing options...
Barand Posted April 30, 2015 Share Posted April 30, 2015 Instead of output buffering, use pagination with mysql LIMIT clause. http://lmgtfy.com/?q=mysql+pagination Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/#findComment-1510385 Share on other sites More sharing options...
Torrie Posted April 30, 2015 Author Share Posted April 30, 2015 Barand, you are a beautiful spirit. I'll give mySQL pagination a try! p.s. (how on earth do people KNOW stuff like this?!? I've been doing php/mysql 10+ years, never heard of it!) Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/#findComment-1510434 Share on other sites More sharing options...
Ch0cu3r Posted April 30, 2015 Share Posted April 30, 2015 I've been doing php/mysql 10+ years, never heard of it! What! So in the 10 years you have never heard of or done paged results from from a database? Its one of the things I first learned when dealing with PHP/MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/#findComment-1510435 Share on other sites More sharing options...
gizmola Posted April 30, 2015 Share Posted April 30, 2015 Barand, you are a beautiful spirit. I'll give mySQL pagination a try! p.s. (how on earth do people KNOW stuff like this?!? I've been doing php/mysql 10+ years, never heard of it!) Torrie, that is a highly amusing statement to most of the experienced folks and I'm not sure how to explain it without knowing a lot more about the context of your (10+ years of php/mysql) claim. Either you have been dependent on other people to have done the heavy lifting for you in the past, or you've been isolated in a legacy environment, or you have just plain been missing the opportunity for mentoring. LIMIT is such a basic aspect of mysql, one has to wonder what other things you don't know about relational databases in general and mysql specifically. I don't mean any offense, and I commend you for your honesty, because frequently people are loathe to admit what they don't know or understand and that can be a problem for them as well. I have to admit I'm really curious, because it would be one thing if you had done 10 years of PHP without a database, but it's another thing entirely to say you've done PHP/MySQL for all that time and never seen LIMIT. In order to miss it you must never have looked at the mysql manual page or seen a tutorial, or been completely unaware of the concept of pagination. Since you did ask: in general people who exhibit basic curiosity, and spend time googling, reading and participating in communities like this one tend to become better more experienced and knowledgable developers over time. I think it requires a desire to understand concepts and code snippets, and show a willingness to invest research time in those pursuits. Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/#findComment-1510439 Share on other sites More sharing options...
gizmola Posted April 30, 2015 Share Posted April 30, 2015 Along the same lines, and in terms of the original question, while we already established that LIMIT and pagination is the best practice, I wonder if you actually read the manual page for the buffering functions you used. If you read the page on ob_end_flush you would see this: This function will send the contents of the topmost output buffer (if any) and turn this output buffer off. If you want to further process the buffer's contents you have to call ob_get_contents() before ob_end_flush() as the buffer contents are discarded after ob_end_flush() is called. See the problem with your code? Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/#findComment-1510442 Share on other sites More sharing options...
Torrie Posted May 1, 2015 Author Share Posted May 1, 2015 (edited) No, you pompous dipshits. I need ALL the records to appear on one page. I thought your stupid mysql pagination suggestion was some way to do some loop (i.e. look up a few records at a time and output to browser in segments), but none of you fagt geeks read my question. I want ALL the records to appear on the same page. Anyway, forget it. Oh, and don't give me this "old timer" crap -- most of you aren't even in college, except for one or two of you that I know to be worms from the old Perl usenet forum. Edited May 1, 2015 by Torrie Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/#findComment-1510488 Share on other sites More sharing options...
QuickOldCar Posted May 1, 2015 Share Posted May 1, 2015 Glad nobody helped you. Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/#findComment-1510494 Share on other sites More sharing options...
cyberRobot Posted May 1, 2015 Share Posted May 1, 2015 I need ALL the records to appear on one page. I thought your ... pagination suggestion was some way to do some loop (i.e. look up a few records at a time and output to browser in segments), but none of you ... read my question. For what it's worth, the original question asked if there was a better way or if you were on the right track. Barand and the others were directing you down a different path. Unless I missed it, the original question didn't state that all the records needed to be on the same page. If that's truly the case, then pagination might not be the answer. With that said, I can understand your frustration. But there's no reason for the offensive language and calling people names. This type of activity will likely lead to you being banned from the forum (note the Forum Rules). Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/#findComment-1510505 Share on other sites More sharing options...
Torrie Posted May 1, 2015 Author Share Posted May 1, 2015 cyberRobot, I disagree; some people NEED to be called out, and called names. Especially those who seethe with resentment, so much so that their answers are tainted. Consider this: let's say that instead of all of us being "on this page here in the forum," we were all sitting around a table in a cafeteria. Nobody but nobody would *ever* respond to me the way all of 'you' responded. Gizmola wouldn't have gone on and on redundantly re-referencing my ...erm... "claim" (as he called it) to using PHP for 10 years (not to mention using the phrase "actually read" the manual page). Treating me like an accused perpetrator on a stand. weird weird weird. Or, pasting a condescending link "here let me google that for you." Here, allow me to wipe the sweat from your brow... Nope no no no. Jerks need to be called jerks. Banning me is a joke. Go ahead and ban me. The next time I ever need this forum, I'll have forgotten the fake username/password anyway, I'll just log in under a different name. How about "Trisha19?" All you fat ugly pimply-faced geeks will jump in and help because they think some hot female is asking the question. And, in conclusion, I'm "claiming" to go now. Bye. Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/#findComment-1510525 Share on other sites More sharing options...
CroNiX Posted May 1, 2015 Share Posted May 1, 2015 Good luck with that attitude! Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/#findComment-1510553 Share on other sites More sharing options...
jcbones Posted May 1, 2015 Share Posted May 1, 2015 hey, I'm not pimply faced. Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/#findComment-1510555 Share on other sites More sharing options...
Trisha19 Posted May 2, 2015 Share Posted May 2, 2015 hey, I'm not pimply faced. Well Hi there JC, how are you? My web-page loops through and echoes all 50,000 entries from a several-column mySQL database (part number, price, description, etc.). It is tedious for me, because It takes about a full minute for my browser to completely load it. I had an idea: Use "ob_start" at the beginning of the script, and insert an "ob_end_flush()" assertion in my "while" loop to get executed every 50 loops, like this: <?php ob_start(); ## access big mySQL database and output it to browser $i=0; while ( $a_row = mysql_fetch_assoc($result) ) { # echo output to browser if($i %50 == 0) { ob_end_flush(); } } ?> That cut the time down from 60 seconds down to about a second and a half. The problem is, the results are goofy (several mySQL rows missing, didn't get output to browser). Is there a better way? Or, am I on the right track? And, if I'm on the right track, what can I do to fix this? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/#findComment-1510572 Share on other sites More sharing options...
gizmola Posted May 2, 2015 Share Posted May 2, 2015 No, you pompous dipshits. I need ALL the records to appear on one page. I thought your stupid mysql pagination suggestion was some way to do some loop (i.e. look up a few records at a time and output to browser in segments), but none of you fagt geeks read my question. I want ALL the records to appear on the same page. Anyway, forget it. Oh, and don't give me this "old timer" crap -- most of you aren't even in college, except for one or two of you that I know to be worms from the old Perl usenet forum. Ok, great, so we can dispense with the curiosity aspect of it. You just made up some wild claim of a decade of php development experience for god knows what reason. You're not an experienced php developer. That was pretty evident from the get-go and really wasn't that great of a charade. Stop kidding yourself that your question was some model of clarity right out of the back of Eric Raymond's dissertation on the subject. Most of us found the idea of spitting out a 10k row html table to be far too ridiculous a premise to be what someone would actually want. Google was not involved. I quoted the manual page for a function you used, but did not understand. If you actually read what was quoted to you, and spent a second trying to understand it, you'd understand why you got your so called "Goofy results" and possibly you'd use that monster intellect of yours to fix your code, which would probably take all of 30 seconds. Your comments in regards to a community of people who donate their time helping others try to improve their skills make you look sad and petty. If indeed most of the people who responded are far younger than you, what does that say about you? Quote Link to comment https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/#findComment-1510573 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.