I am new to php and recently inherited a very basic shopping cart where I work. My boss is not very bright and has no clue who set it up for him.

When displaying the orders it displays about 1 per second or slower.. very slow when you have about 10,000 orders sitting there to be done and you're seafching for one. Or if someone is on the phone and their order is at the bottom of the list.

From what I see in the code, it does a simple read from a mysql DB reading only the order#, name, and order status (which is just a check box) then it displays it on a website. Seems very basic to me. Although it is capable of doing a little more, this is all we have it doing.

Why is it so slow? I know it's not the server because I have a copy on my testing server here next to me and it's the same speed.

stumped,
Adam

    Probably very badly written code.

    HalfaBee

      probably, but I cannot re-write it. Well, i'm sure i can. Is there any temporary quick fix?

        If you are looking for just 1 order surely it can just retrieve the 1 set of data .

        Without seeing the code it is very hard to suggest a quick fix for your situation.

        HalfaBee

          there's a crapload of code in different files. I could show the code from the display page, but it just links to others

            You might have to employ a programmer to fix your problem.
            I doubt if anyone will do it for free. 🙁

            HalfaBee

              Install the Zend Optimizer or even the Accelerator. You should be able to get a better result on executing time, but not for sure on a badly written code that does a simple task. How big is each page? Does it have lots of loops?? If you see a nested loops, then that might be the reason.

                Hmmm, it MIGHT be because you call 70+ items on one page but I'm thinking you might have some weird extra loop in there that slows it down even more than that, double and triple checking orders or something. Try splitting up the query by recordcount and page?

                I.E. 25 orders displayed per page?

                  I see your point, but these meager beings that look for orders are dumb.. and making sudden changed (suptle as they are) would confuse them.

                  Should I put a search field and limit it to 25 per page you think?

                  -adam

                    You know, I just sat here and thought about what I just posted and noticed that I just confused the crap out of myself.

                    Questions:

                    1.) If I want a search field for a certain order number in the entire db to appear, I would put that in the Orders.php, correct?

                    2.) What would the line of code look like for displaying only 25 per page?

                    I know I will have to custom taylor it, but I am very new to php (like a week) but have worked with perl.. I just need to know what it might look like.

                    thanks a million
                    -adam

                      Off the top of my head I can't remember it but get the total recordcount for the query before you start outputting them. Then loop through the result set only 25 times and set a number to figure out where the last one you got was so you can display the next 25 when hitting a "next>" button or "page 2" or what have you. And I'm usually satisfied with a search when I can at least click the top link to "Order By" and sort the records based on my needs. So clicking "Date" would sort by date, "Name" by last name or first name or whatever, so on and so forth.

                        Yes you need a
                        <input name=findme >

                        and in orders something like this

                        if( isset( $_GET['findme'] ) ) {
                        // your mysql query +  WHERE order_number=$findme
                        
                        // do html bit here
                        }
                        

                        I bet the incomplete order section grabs the whole DB and loops thru it looking for incomplete orders, rather than doing a WHERE in the SQL.

                        HalfaBee

                          What db is this sitting on ... and is the db host the same on the "test" server sitting next to you as it is on the slow 'production' box?

                          And HalfaBee's got a good thought there ... poorly designed db schema could be part of the issue.

                          Got a DB admin tool handy that might say something about the server load, errors, etc?

                            I edited some code earlier and tested 2 different DB servers. Mine, and the one currently in use at the business. My SQL server is much much faster than the one in use. I think the other one is NT4 where as mine is Solaris. Which means a lot 🙂

                            I have phpMyAdmin, but that's on my server and i'm not getting any errors.. as for the other one, I do not have full access.. but the DB in use isn't showing any errors.

                            -adam

                              Originally posted by somedudeppf
                              I edited some code earlier and tested 2 different DB servers. Mine, and the one currently in use at the business. My SQL server is much much faster than the one in use. I think the other one is NT4 where as mine is Solaris. Which means a lot 🙂

                              I have phpMyAdmin, but that's on my server and i'm not getting any errors.. as for the other one, I do not have full access.. but the DB in use isn't showing any errors.


                              -adam

                              NT4 could defnitely be a big SNAFU ... has been quite a while, IMHO. Solaris? Dunno. In cruising auburn.edu and digging for info, I'd say that you're not in an ultra-high speed environment there, either.

                              Suppose there's any chance that it's slow in one place for one reason, and slow in the other for a different one?

                              The other option would be to SUTC - "Show Us The Code" and let us see what we think. Heck, you've already let us into your control panel ... what've you to lose ? 😉

                                hell, i don't care if you see the code or not.. it's not like it's some huge secret code. auburn.edu is faster than i had imagined (i worked for an internet service long before coming here) they waste all of the student's money on fiber and gigabit switches (which they "need so desperatly")

                                here's a zip of the code

                                  The problem is here

                                  function ExecuteQuery($MysqlQuery) {
                                  	$MysqlInfo = MysqlInfo();
                                  	$link = mysql_connect($MysqlInfo[0], $MysqlInfo[2], $MysqlInfo[3])
                                      	or die("Could not connect");
                                  	mysql_select_db($MysqlInfo[1])
                                      	or die("Could not select database");
                                  
                                  // Performing SQL query
                                  $result = mysql_query($MysqlQuery)
                                      or die("Query failed");
                                  
                                  // return array
                                  return $result;
                                  
                                  // Closing connection
                                  mysql_close($link);
                                  }
                                  

                                  The link is opened and closed everytime this is executed.
                                  Remove the mysql_close() and it will be quicker.

                                  Halfabee

                                    Same logic is used in the next function (ExecuteNonQuery) and call to close could be omitted.

                                    Perhaps even better would be one call to mysql_pconnect at each page load ... both of these functions are calling the link each time, and a permanent db connection established at the start of the script might speed things up even more.

                                    But, props to HalfaBee ... one smart insect. I wouldn't have found it myself .... 😃

                                      props to both of you :-)

                                      This is in the queries.php, right? I'm trying it now.. will let you know how it goes.

                                      HalfaBee.. I used to have a network with servers named bee. KillaBee, SupaBee, YoSupaKillaBee.. etc. that was off the subject, but still..

                                      -adam