--- Luis Lebron <[EMAIL PROTECTED]> wrote:
> I am rebuilding a php application to handle a higher load. The
> previous programmer had created a series of dynamically generated
> select boxes using a mysql table. Would it be faster or less
> resource intensive to create a series of arrays to generate the
> select boxes and avoid the database queries. I've done some informal
> testing using Pear Benchmark and it seems the array based script
> usually takes less time.

Basically, anything you can do to eliminate talking to the database will
usually improve performance by a fair margin. The downside is convenience; if
you have data hard-coded in your PHP scripts, it is less convenient to maintain
the data. You effectively eliminate the separation between the data and your
logic.

A similar idea is to eliminate PHP. Apache can serve a lot more static pages
than it can PHP pages at any given time. Of course, this has a similar
disadvantage as well. Now your pages are static rather than dynamic.

Developers have created many different types of systems to address these
thoughts. For eliminating database queries while still leaving the data in your
database, you simply need something to update your PHP scripts whenever data in
the database changes, or at regular intervals. For example, you mention an
array replacing the query. This array can be in a separate include file and act
as a sort of cache. This cache can be refreshed as often as appropriate using
another PHP script that you write.

The same idea can be applied to static pages. These can also be refreshed with
PHP scripts as often as necessary. In fact, you might want to just do something
like this and not even worry about limiting database interactions with your PHP
script, since it won't be executed but a fraction of the time.

So, your instincts serve you well. In general, anytime you query the database
many times to receive the exact same data, there is probably a better solution.
In the same sense, anytime the output of a PHP script is the same for many
users, there is probably a better solution.

Hope that helps.

Chris

=====
My Blog
     http://shiflett.org/
HTTP Developer's Handbook
     http://httphandbook.org/
RAMP Training Courses
     http://www.nyphp.org/ramp

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to