Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/295962-ob_start-to-speed-up-experience/
Share on other sites

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.

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?

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 by Torrie

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).

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.

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.

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.  

 

  1. 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. 
  2. 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.
  3. 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?
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.