Hi
Undskyld for ubelejligheden at mit spoergsmaal er paa egelsk, men
da jeg har skrevet saa meget og skrev det ind paa et engelsk
forum foerst ville jeg ikke ogsaa skrive det paa dansk.
QUESTION:
Why is the code running so slow and what can I do to improve it?
THE CODE:
$currentTable = "SS_products";
$q1 = db_query("SELECT FLOOR(RAND() * COUNT(*)) AS rand_row FROM
".
$currentTable) or die (db_error());
$row1 = db_fetch_row($q1);
$q2 = db_query("SELECT categoryID, name, default_picture FROM ".
$currentTable." WHERE categoryID=7 Limit $row1[0], 1") or die
(db_error());
Background Infomation on the Code:
I have a website where I use a shopping cart system called
ShopScript Premium. This system works more then fine with my
current webhost BlueHost. But a problem arises when I add
customized the code.
I have added to the website home page that every time the browser
is refreshed 10 new random products will be the customers. The
ShopScript system only offers products which are to be changed by
the administrator manually. When the code for the random product
is executed the website runs considerably slower then without the
random products, although sometimes and does run with no problems
and fast speed for a minute or so. Even if the user is using the
other pages the website is still slow. I suspect this has to do
with the fact that the ShopScript system uses a smarty engine,
although that does not fully explain why.
In my database the table called has 1373 rows. I use the code
above to randomly select one of the rows to be viewed on the
website. According to my log on mySQL slow queries, the above
mentioned code, is the source of the problems. The log states
that the code uses 2 to 4 seconds query time. My webhost does not
allow any single process taking more than 30 CPU seconds to run
or if the total processes take more than 40 CPU seconds in any 60
second window to avoid server lockups. Such an event triggers a
CPU Quota/Suspension Error, where my website is accessable for 5
to 10 minutes. This is a big problem as I lose customers this
way.
--
Vil du lære at kode HTML, XHTML, CSS, SSI, ASP eller ASP.NET?
- Pædagogiske tutorials på dansk
- Kom godt i gang med koderne
KLIK HER! =>
http://www.html.dk/tutorials