简体   繁体   中英

database driven site has become slow in initial page load

I have developed a database driven website which is actually a content management system as well. It is mainly for my own use but it is also a uni project.

I am not quite sure at what point it happened but it now seems to have a very slow initial load time. It takes at least about 6 seconds to load now and is sometimes quite a bit slower. Once it is loaded initially it is almost instantaneous in reloading or loading any other page. If you leave it and then go back to it after a while (not sure exactly how long... maybe a minute or 2) it will take 6 seconds or more to load any page again.

I used webpagetest.org and the results showed that time to first byte is very high (sometimes as much as 10 seconds). I can attend to other problems like image sizes at some other time but it is that initial page load that needs to be resolved. If it is something to do with the php include files then why do pages load instantly after the initial load?

I know I should have investigated it as and when it first seemed to slow down but unfortunately I just cannot pinpoint the exact time. I have searched on google about slow loading speeds and I can find no one who is giving any real advice about genuine slow loading problems. It is all just basic stuff like "make sure you don't have too many separate CSS documents" or "don't use large images". Apart from the fact that those are common sense they are also pretty insignificant...

I will throw out some ideas just to see if anyone can confirm a general design flaw in the site itself.

I used to connect to the database individually in every include file that used the database but then thought that that seemed unnecessary so now I just connect to the database at the start of all the pages(I fclose at the end of each main page as well). Should I connect to the database on all include files or is this illogical?

The pages all start with a connection to the database and the links in the head are retrieved from the database. There is more than one CSS file admittedly but I cannot see that causing much time to be added to the initial page load.

All article content including the home page is loaded directly from the database.

Surely this has to do with some caching that is occuring somewhere. However, with the information you give it's impossible to determine what exactly is taking so long. Do you use any PHP frameworks or libraries? What is your setup? ...

That being said, 6 seconds for an uncached page is still a huge amount of time, so there will be some inefficient code or DB design. But you cannot expect a silver bullet here. To be able to judge the performance, one would need to see the entire code and the problem can be a combination of a lot of bad choices...

如果您的网站上有社交按钮(fb / twitter / g +等),它们可能会大大降低网站速度

Sounds like a caching issue to me. Regarding on information you provided, it shouldn't be browser side. I also have a feeling like you don't use any php opcode cacher. 2 other possible reason that comes in my mind are, external resources or slow mysql connection&query on first time for some reason. Last has the highest possibility in my opinion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM