Re: Advice about fetching user information



In article <qaydnYZn7rlKvfvYnZ2dnUVZ_qmdnZ2d@xxxxxxxxxxx>,
Jerry Stuckle <jstucklex@xxxxxxxxxxxxx> wrote:

Eh? I *AM* using MySQL. As shown in my code above. Using MySQL for
this takes too long.

OK, I thought you were saying the information you're after was not on
the database. My misunderstand.

No problem.

What's "too slow"? 1 second? 10 seconds? 100 seconds? How many rows
are you talking about?

Everything over 0.1 seconds is way too slow. Today the tables contains
about 9000 members, and the time it takes to fetch information about
them takes around 0.8 seconds, but actually *selecting* them in MySQL
only takes about 0.16 seconds, the rest of the time, I'm assuming, is
moving that data from MySQL to a PHP array.

I assure you that I am quite conscious about time consumptions in my
PHP scripts and use a gauge() function to time pretty much every
important part of producing the HTML for a web page. Each millisecond
counts and I have a performance warning system that activates when a
page takes longer than 2 seconds to create.

All my MySQL tables are quite optimized along the usual optimization
tricks with regards to indexing and direct/matching queries.

Sure, you can implement this in flat files. But it's going to take
longer to search your flat files in PHP than MySQL does in compiled
code. The same is pretty much true for searching an array in PHP -
small arrays are faster, but as the array grows, the difference becomes
less.

But I wouldn't be searching. The flatfile would be named
"/path/to/aggregate/members/2837.txt" or something like that.

The data in that could even be serialized for easy management, so
reading it would be like:

function member_name($id){
$member = unserialize(join("", file("/path/to//2837.txt")));
return $member["name"];
}

Problem with this is that this information needs to be aggregated once
in a while...

Plus, what I'd like to know is if:

$member = unserialize(join("", file("/path/to//2837.txt")));

Is faster than:

$q=mysql_query("select x, x, x from member where id = 2837");
$member = mysql_fetch_array($q);

I guess I have to test it. I was hoping that someone here might have
known or knew of a third option for doing the same thing.

You'd be much better off optimizing your database (and the database
design, if necessary), and potentially your queries. I can't see why it
should take all those queries to get the info you want.

It's just one query... And that query takes, today, 0.8 seconds, which
is too long. And when the member count grows, it will take longer and
longer.





--
Sandman[.net]
.



Relevant Pages

  • php/mysql puzzler
    ... wrapper function I've written to insert an array in a table. ... What is weirder is that it works fine on my local server -- I only get ... php or mysql setting that may have unintended consequence elsewhere. ...
    (comp.lang.php)
  • Re: Manipulating date with "00" in it coming from mySQL
    ... //If array has no number month and thus cannot have a number for day: ... It appears that since I do have some pre-1970 dates and I don't want to display unknown days as 01 that using the date options of either PHP or mySQL won't do what I want. ...
    (comp.lang.php)
  • Counting matches
    ... This is really more of a MySQL question than PHP per se, ... MySQL group my newserver carries seems to be pretty quiet, ... This array is then looped over to pass each word to an SQL ...
    (comp.lang.php)
  • Re: [PHP] a better way to do a data import?
    ... I've had php cycle through the file row by row and if the row is there, ... a default array I have in the class so I can have key value pairs. ... In MySQL, I could simply a replace on ... database dumps surrounding the inserts: ...
    (php.general)
  • Re: Searching for a specific line within a file
    ... Obviously, I'd like to avoid reading in the entire contents of the file then say, explodeing into an array, then searching the array for the contents of the line to print. ... There isn't any PHP function to do that automatically, which leaves you the choice of reading the whole file in at once, or read it one line at a time, looking for the one you want. ...
    (comp.lang.php)