缓存!解决PHP的性能问题Cache it! Solve PHP Performance Problems
原站著录信息
摘要
Abstract:In the good old days when building web sites was as easy as knocking up a few HTML pages, the delivery of a web page to a browser was a simple matter of having the web server fetch a file. A site's visitors would see its small, text-only pages almost…
Abstract:In the good old days when building web sites was as easy as knocking up a few HTML pages, the delivery of a web page to a browser was a simple matter of having the web server fetch a file. A site's visitors would see its small, text-only pages almost immediately, unless they were using particularly slow modems. Once the page was downloaded, the browser would cache it somewhere on the local computer so that, should the page be requested again, after performing a quick check with the server to ensure the page hadn't been updated, the browser could display the locally cached version. Pages were served as quickly and efficiently as possible, and everyone was happy.
Then dynamic web pages came along and spoiled the party by introducing two problems:
When a request for a dynamic web page is received by the server, some intermediate processing must be completed, such as the execution of scripts by the PHP engine. This processing introduces a delay before the web server begins to deliver the output to the browser. This may not be a significant delay where simple PHP scripts are concerned, but for a more complex application, the PHP engine may have a lot of work to do before the page is finally ready for delivery. This extra work results in a noticeable time lag between the user's requests and the actual display of pages in the browser.
A typical web server, such as Apache, uses the time of file modification to inform a web browser of a requested page's age, allowing the browser to take appropriate caching action. With dynamic web pages, the actual PHP script may change only occasionally; meanwhile, the content it displays, which is often fetched from a database, will change frequently. The web server has no way of discerning updates to the database, so it doesn't send a last modified date. If the client (that is, the user's browser) has no indication of how long the data will remain valid, it will take a guess. This is problematic if the browser decides to use a locally cached version of the page which is now out of date, or if the browser decides to request from the server a fresh copy of the page, which actually has no new content, making the request redundant. The web server will always respond with a freshly constructed version of the page, regardless of whether or not the data in the database has actually changed.
……
摘要:在这个建设网站跟建一段HTML页面一样简单的好时期,对于浏览器来说传送一个网页如同从网络服务器上获取一个文件一样是件简单的事情。网站的访问者几乎立即会看到 比较小,且只支持文本的网页,除非他们使用特别慢的调制解调器。一旦网页被下载,浏览器会缓存在本地计算机上某个地方,这样,如果再次要求页面后,服务器执行快速检查,以确保该网页没有更新,浏览器可以显示本地缓存版本。网页将迅速和尽可能高效率地显示,这样对大家都是件高兴的事情。
……
Then dynamic web pages came along and spoiled the party by introducing two problems:
When a request for a dynamic web page is received by the server, some intermediate processing must be completed, such as the execution of scripts by the PHP engine. This processing introduces a delay before the web server begins to deliver the output to the browser. This may not be a significant delay where simple PHP scripts are concerned, but for a more complex application, the PHP engine may have a lot of work to do before the page is finally ready for delivery. This extra work results in a noticeable time lag between the user's requests and the actual display of pages in the browser.
A typical web server, such as Apache, uses the time of file modification to inform a web browser of a requested page's age, allowing the browser to take appropriate caching action. With dynamic web pages, the actual PHP script may change only occasionally; meanwhile, the content it displays, which is often fetched from a database, will change frequently. The web server has no way of discerning updates to the database, so it doesn't send a last modified date. If the client (that is, the user's browser) has no indication of how long the data will remain valid, it will take a guess. This is problematic if the browser decides to use a locally cached version of the page which is now out of date, or if the browser decides to request from the server a fresh copy of the page, which actually has no new content, making the request redundant. The web server will always respond with a freshly constructed version of the page, regardless of whether or not the data in the database has actually changed.
……
摘要:在这个建设网站跟建一段HTML页面一样简单的好时期,对于浏览器来说传送一个网页如同从网络服务器上获取一个文件一样是件简单的事情。网站的访问者几乎立即会看到 比较小,且只支持文本的网页,除非他们使用特别慢的调制解调器。一旦网页被下载,浏览器会缓存在本地计算机上某个地方,这样,如果再次要求页面后,服务器执行快速检查,以确保该网页没有更新,浏览器可以显示本地缓存版本。网页将迅速和尽可能高效率地显示,这样对大家都是件高兴的事情。
……
