1

I have got a simple PHP page requesting a list of addresses from a MySQL database. The database table has got 1257 entries. I also include a dynamically loaded side menu to browse to other sites. Together I got 5 MySQL requests

  1. The addresses
  2. Pagination
  3. Check whee the user has got permission to browse
  4. get all the groups for side menu
  5. get all sub entries for side menu

The site takes about 5 seconds to load.

I Googled for site load time improvement and found the Google Developer tools with page speed did all the improvements it told me to like enable deflate, change banner size, and so on but it is still at nearly the same loading time. I would like to know if this is common or if there anything I can do to improve the loading time.

EDIT: I have also indexed the columns and enabled the MySQL cache. I also use foreign keys in the sub entries table which are from the menu group table

EDIT2: I found the solution the problem was that i used localhost to connect to my db but since im using windows 7 it tried to connect via ipv6 now i change all localhost to 127.0.0.1 and it only takes about 126ms to load my page

5
  • i think 1257 very small queries will only take milli sec .may be you are loading images and refering resources from some other site that might be taking time .or you may be using a poor server Commented Feb 27, 2013 at 10:54
  • i used xampp on my local machine it got 8gb ram ,a SSD and 3GHz Quadcore CPU. so since the server is basicly localhost i should have issues with loading stuff the querys take about 0,02 sec each if i execute them in phpmyadmin and thats exactly why i am so confused. Commented Feb 27, 2013 at 10:57
  • 1
    I would suggest that you record the time at various points in the script (use microtime(true) to get the time), then put them out at the end of the script to try and find which section of the code is taking time. You can put more time checks in those areas to get it even more nailed down. Also try your SQL queries individually in phpmyadmin or equivalent with an EXPLAIN and check that the indexes really are being used. Commented Feb 28, 2013 at 9:31
  • using microtime(true) i found out that i lose 1 sec just for this line mysql_query("SET NAMES 'utf8'"); and also 1 second to connect to the db is that normal? Commented Mar 4, 2013 at 13:44
  • also the queries take about 0.04 sec at most Commented Mar 4, 2013 at 13:51

2 Answers 2

1

In the first place, find out what's taking a page so long to load with browser's console. If the cause of the delay is at server side, e.g. the html file itself is being generated for a long time, then check the following:

Try to log slow mysql queries and make sure that you have none. http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html

If you really have some expensive calculations going on (which is not likely in your case), try to cache it.

Don't forget about benefits of PHP code accelerators like APC and mysql optimizations (query cache etc).

... many other ways to speed things up, but got to profile the app itself and see what's going on.

Sign up to request clarification or add additional context in comments.

Comments

0

Have you done indexing for the columns using in where condition. If not pl index the columns and check it

3 Comments

sry totally forgott to mention that yes the colums are indexed
1) if the page having more image make sprites 2) Add all js files bottom of the page 3) check the apache keepalive is ON
only 1 image(banner),keep alive is on,js files are at the bottom

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.