RE: [PHP] Performance of dynamically generated select boxes

2003-10-30 Thread Luis Lebron
--- 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.

--- Chris Shiflett wrote:
>>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.


I figured that writing the select boxes as plain html would be the fastest
solution. However, I did not know of a way of repeating back the database
contents using plain html. Now I can compare the the array with the database
information and show the previously selected element in the select box. 

The data is fairly static (i.e. states, countries, etc) so I just created an
include file with the arrays and include it as needed.

Thanks for the feedback.


Luis



Re: [PHP] Performance of dynamically generated select boxes

2003-10-29 Thread Chris Shiflett
--- 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



Re: [PHP] Performance of dynamically generated select boxes

2003-10-29 Thread CPT John W. Holmes
From: "Luis Lebron" <[EMAIL PROTECTED]>


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

Yeah, that would be quicker, provided the contents don't change to often.
You should build a cache system where the arrays are recreated every so
often so they stay current (or on demand).

Take a look at var_export(). It will return valid PHP code that you can
write to a file and then include() to recreate your arrays. If the file
doesn't exist, trigger the function to create the array file, etc...

---John Holmes...

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



[PHP] Performance of dynamically generated select boxes

2003-10-29 Thread Luis Lebron
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.

thanks,

Luis R. Lebron
Project Manager
Sigmatech, Inc