简体   繁体   English

数据库驱动的站点的初始页面加载速度变慢

[英]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. 它主要供我自己使用,但它也是一个uni项目。

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. 现在至少需要6秒钟才能加载,有时会慢很多。 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. 如果您离开它,然后过一会儿再返回它(不确定确切的时间...可能是一分钟或2分钟),则需要6秒或更长时间才能再次加载任何页面。

I used webpagetest.org and the results showed that time to first byte is very high (sometimes as much as 10 seconds). 我使用了webpagetest.org,结果显示到第一个字节的时间非常长(有时长达10秒)。 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? 如果与php include文件有关,那么为什么页面在初始加载后立即加载?

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. 我已经在Google上搜索了有关缓慢加载速度的信息,但找不到任何人对真正的缓慢加载问题给出任何真正的建议。 It is all just basic stuff like "make sure you don't have too many separate CSS documents" or "don't use large images". 这些都是“确保您没有太多单独的CSS文档”或“不要使用大图像”之类的基本内容。 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. 承认有多个CSS文件,但我看不到这会导致将大量时间添加到初始页面加载中。

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? 您是否使用任何PHP框架或库? 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. 话虽这么说,未缓存页面的6秒仍然是很长的时间,所以将存在一些效率低下的代码或数据库设计。 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. 我也有一种感觉,就像您不使用任何php操作码缓存。 2 other possible reason that comes in my mind are, external resources or slow mysql connection&query on first time for some reason. 我想到的2个其他可能原因是外部资源或由于某种原因第一次导致mysql连接和查询速度缓慢。 Last has the highest possibility in my opinion. 我认为倒数第二个可能性最高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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