Server Load, Multiple Queries, PHP and Arrays ...
| From: | Jak | Date: | Sun, 17 Sep 2000 16:35:46 +0000 |
| Subject: | Server Load, Multiple Queries, PHP and Arrays ... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-17075@lists.php.net to get a copy of this message | ||
Hello, I am writing some code in order to create a php script that will run
from a cron each hour,
and will send news written in the last 24 hours based on user preferences,
that may be about
category or subject type ....
As an user is allowed to choose multiple subjects, I've created a table
field where the subjects are
stored like "-1-5-7-13-" .... whereas in the news table, a single news, of
course can have only one subject ....
Anyway, my question is about server performance:
Let's imagine a 10.000 users to be mailed work load, for a given hour ... I
extract those user from the database
table, where I have
mailinglistID (autoincrement, etc..)
userID (numeric, 1, 5, 13, etc...)
categoryID (only one allowed , 5, 69, 1341)
subject_list (like I said, "-1-5-7-13")
hour (1 or 2 or .... 24)
So let's say I have 10.000 users for a given hour ..... 10 a.m. ....
My way:
I extract the users for that hour (10000 records)
I then need to extract the news to send out, so for the sake of simplicity,
I extract all the news in the last 24 hours for that
given category, don't caring for now about subject (I'll reduce items at a
l8r step ) ... this query can produce approx 10 results, not much infact
....
Now .... I need to build out the mail to send out to the various users,
based on their subject_list preferences ....
And here is the problem:
Is it better if I put all the news into an array, and work w/ the array,
extracting only news corresponding to the subject_list, looping 10.000 times
trough the array and extracting ....
(and , how do I append values to an array? Say I have news = array ( title
=> "blah", body => "blah"), for news 1, how do I add a second couple
of title, body ..... to the array? )
Would this way of proceeding (10000 interactions w/ the array) will be very
resource demanding?
Would it be better to do 10.000 queries, each w/ a given preference ( if
two users have same preferences, I could do 1 query, as I could order
results so the same will be together, but on 10.000 that could reduce to
about 7.000 or so?)
So is it worse resource wise to ask mysql 7000 times, or ask mysql say 500
times (for the various categories), and then work w/ arrays?
(consider that system also needs to do the mail out, etc....)
What do I have to expect?
Thanks to all that will help ....
Greetz from Italy! :-)