473,466 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

include file vs db queries

Hello,

I'm programming an Amazon type web site and find myself "wasting" a
lot of time writing code that gets information from include files
rather than from the database because I have this notion that it will
avoid clogging the db when many users come to the site. My main goal
anyway is to have the user wait as little as possible because that's
good for business apparently.

Here's an example:

When the user will be checking out a certain product I'll have to
display at the top of the page the product category path. For instance

Products > Electronics > Computers > Laptops > Accessories > Mouse

If I wanted to code quickly I could write a function that builds this
path by querying the database and run the function every time someone
accesses a page. Instead I have a folder "Paths" containing an include
file for every category possible. For example: "path_category_32.inc".
In my web page I do something like

include("path_category_".$_GET['cat_id'].".inc");

and the file contains:
echo "Products > Electronics > Computers > Laptops > Accessories >
Mouse";

I have code that generates these include files and I only have to run
it when a category is added, removed or renamed - which will be rare.
Is this not a lot better than querying the database 1000 times a day
just to get information that is static? Now this was one example but
there are many other elements I could apply this method to. The
problem is that it takes a lot longer time to code and I also have a
delivery date to meet, yet I don't want to deliver something that is
not efficient because it queries the db all the time.

Any advice?
Jul 17 '05 #1
6 1981
zorro wrote:
Hello,
I have code that generates these include files and I only have to run
it when a category is added, removed or renamed - which will be rare.
Is this not a lot better than querying the database 1000 times a day
just to get information that is static? Now this was one example but
there are many other elements I could apply this method to. The
problem is that it takes a lot longer time to code and I also have a
delivery date to meet, yet I don't want to deliver something that is
not efficient because it queries the db all the time.

Any advice?


Not that I know a great deal about the subject, but I do know some
databases will cache the querys so if you submit multiple queries that
return the same thing, the dbms will simply return the cached results
and not bother searching the database again. For something like
generating those paths, I assume this mechinism would kick in and thus
using files or a database probably wouldn't make that big of a
difference speed wise.

Also to go along with the cached queries, make sure you are using SQL to
its full potential and doing things in the smallest number and most
efficient queries possible. Use table joines, group functions, etc. to
produce the results requied in the fastest time.
Jul 17 '05 #2
zorro wrote:
Hello,

I'm programming an Amazon type web site and find myself "wasting" a
lot of time writing code that gets information from include files
rather than from the database because I have this notion that it will
avoid clogging the db when many users come to the site. My main goal
anyway is to have the user wait as little as possible because that's
good for business apparently.

Here's an example:

When the user will be checking out a certain product I'll have to
display at the top of the page the product category path. For instance

Products > Electronics > Computers > Laptops > Accessories > Mouse

If I wanted to code quickly I could write a function that builds this
path by querying the database and run the function every time someone
accesses a page. Instead I have a folder "Paths" containing an include
file for every category possible. For example: "path_category_32.inc".
In my web page I do something like

include("path_category_".$_GET['cat_id'].".inc");
Aside from your database-file include problem, I hope you're not actually
using this line...
and the file contains:
echo "Products > Electronics > Computers > Laptops > Accessories >
Mouse";

I have code that generates these include files and I only have to run
it when a category is added, removed or renamed - which will be rare.
Is this not a lot better than querying the database 1000 times a day
just to get information that is static? Now this was one example but
there are many other elements I could apply this method to. The
problem is that it takes a lot longer time to code and I also have a
delivery date to meet, yet I don't want to deliver something that is
not efficient because it queries the db all the time.

Any advice?


I don't think a database request will take that much time, if it is just one
query.

Rutger Claes
--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
You will always find something in the last place you look.

Jul 17 '05 #3
zorro wrote:
Hello,

I'm programming an Amazon type web site and find myself "wasting" a
lot of time writing code that gets information from include files
rather than from the database because I have this notion that it will
avoid clogging the db when many users come to the site. My main goal
anyway is to have the user wait as little as possible because that's
good for business apparently.

Here's an example:

When the user will be checking out a certain product I'll have to
display at the top of the page the product category path. For instance

Products > Electronics > Computers > Laptops > Accessories > Mouse

If I wanted to code quickly I could write a function that builds this
path by querying the database and run the function every time someone
accesses a page. Instead I have a folder "Paths" containing an include
file for every category possible. For example: "path_category_32.inc".
In my web page I do something like

include("path_category_".$_GET['cat_id'].".inc");

and the file contains:
echo "Products > Electronics > Computers > Laptops > Accessories >
Mouse";

I have code that generates these include files and I only have to run
it when a category is added, removed or renamed - which will be rare.
Is this not a lot better than querying the database 1000 times a day
just to get information that is static? Now this was one example but
there are many other elements I could apply this method to. The
problem is that it takes a lot longer time to code and I also have a
delivery date to meet, yet I don't want to deliver something that is
not efficient because it queries the db all the time.

Any advice?


I think you will find it is faster and more efficient to use a
database query then to open, read, and close the include file
every time you use it. Bear in mind that database accesses are
very fast (even a slow computer can support several hundred
database accesses per minute) and give you the opportunity to
make changes to your data without having to make corresponding
changes to your code.

HTH
Jerry
Jul 17 '05 #4
zorro wrote:
<snip>
Here's an example:

When the user will be checking out a certain product I'll have to
display at the top of the page the product category path. For instance

Products > Electronics > Computers > Laptops > Accessories > Mouse <snip> Any advice?


As other posters have said I don't think the DB access method is all
that bad :)

However, my first thought to remove the DB access from your code was to
use $_SESSION variables, maybe something like:

<?php
$_SESSION['path'] = array('Products', 'Electronics', 'Computers',
'Laptops', 'Accessories', 'Mouse');
?>

Of course it would have to be changed everytime the user moves around
your site. Then just output it at the checkout page:

<?php
echo implode(' &gt; ', $_SESSION['path']);
?>

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #5
"zorro" <my*****@yahoo.ca> wrote in message
news:1b**************************@posting.google.c om...
Hello,

I'm programming an Amazon type web site and find myself "wasting" a
lot of time writing code that gets information from include files
rather than from the database because I have this notion that it will
avoid clogging the db when many users come to the site. My main goal
anyway is to have the user wait as little as possible because that's
good for business apparently.

Here's an example:

When the user will be checking out a certain product I'll have to
display at the top of the page the product category path. For instance

Products > Electronics > Computers > Laptops > Accessories > Mouse

If I wanted to code quickly I could write a function that builds this
path by querying the database and run the function every time someone
accesses a page. Instead I have a folder "Paths" containing an include
file for every category possible. For example: "path_category_32.inc".
In my web page I do something like

include("path_category_".$_GET['cat_id'].".inc");

and the file contains:
echo "Products > Electronics > Computers > Laptops > Accessories >
Mouse";

I have code that generates these include files and I only have to run
it when a category is added, removed or renamed - which will be rare.
Is this not a lot better than querying the database 1000 times a day
just to get information that is static? Now this was one example but
there are many other elements I could apply this method to. The
problem is that it takes a lot longer time to code and I also have a
delivery date to meet, yet I don't want to deliver something that is
not efficient because it queries the db all the time.

Any advice?


Might as well just go the full route and cache the whole site. It isn't
efficient either to have PHP execute the same code over and over again
yielding the same HTML over and over.

Just touch a file whenever the database is changed. Then, based on the
modified time of this file and that of the cached HTML file, regenerate the
latter as necessary. Implemented correctly, it can give you a big boost in
speed while requiring little intervention.
Jul 17 '05 #6
nc
zorro wrote:

I'm programming an Amazon type web site and find myself
"wasting" a lot of time writing code that gets information
from include files rather than from the database because
I have this notion that it will avoid clogging the db when
many users come to the site. My main goal anyway is to have
the user wait as little as possible because that's good for
business apparently.
If that's your main goal, consider tuning your database server
to allow query caching. For a high-traffic site, think about
multiple database servers with load balancing.
I have code that generates these include files and I only
have to run it when a category is added, removed or renamed
- which will be rare. Is this not a lot better than querying
the database 1000 times a day just to get information that
is static?
If that data is indeed static, query caching should minimize
your overhead...
this was one example but there are many other elements
I could apply this method to. The problem is that it takes
a lot longer time to code and I also have a delivery date
to meet, yet I don't want to deliver something that is
not efficient because it queries the db all the time.

Any advice?


Think beyond coding. Web application performance is often
defined not by how it's written, but by how it's deployed.

Cheers,
NC

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jez | last post by:
I'm ashamed that I need to ask this question. I've been using PHP for almost a year now, and have used HTML extensively in the last few years. Often, when I create a new site, I use include() to...
0
by: zorro | last post by:
Thanks all for your suggestions. I'm definitely scrapping my method for now. I liked the following idea most but I'll probably go with the db method because it's probably easiest to manage. ;)...
3
by: middletree | last post by:
I have a page which, according to the boss's instructions, needs to show one of two things, based on which radio button was chosen on the previous page. Because these 'things' are actually some...
3
by: Gordon Moore | last post by:
Hi, I'm new to using xml/xslt and although I can create an xml document using the dataset.WriteXml statement, and I have created an xslt to transform the xml into the output I want, I have to...
4
by: HEATHER CARTER-YOUNG | last post by:
Please help. I have two databases - one I'm designing that will be our in-house data mgmt system (db1) and another that is a federally-mandated system (db2). We must submit data from db2 but don't...
2
by: David Arden Stevensonn | last post by:
On 'sub1.othercompany.com' there is a simple php file with an include that calls a script on my company's server 'sub2.mycompany.com' The script on my company's server seems to work fine when I...
4
by: Jon | last post by:
All, I have a question regarding include files. I'm currently wanting to secure all of the pages within a directory by having a login script that queries a MySQL DB, and writes a session...
6
by: Stan | last post by:
I am working on a database in ACCESS 2003. This is a simple DB with only one table. I have split the DB so I can upgrade and debug the front end before installing on my clients' computer. I used...
9
by: Bob Bedford | last post by:
HI all, Weird problem.... in the file queries.inc.php I've this: $query = 'select * from list where content = '.$idcontent; I've this code in my page: $idcontent = 15;...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.