让本地主机更快?
我目前正在开发一个项目并在我的本地主机上测试它。
我担心的是页面加载速度非常慢(500-700 毫秒而不是更少)。我认为 localhost 的加载速度比任何其他网页都快(因为它驻留在我的本地计算机上)。因此,如果这些是本地主机上的加载时间,那么将我的站点移动到远程服务器上时它们会明显更大吗?
作为技术细节,我正在 CakePHP 框架上进行开发,并且有几个 AJAX 请求,所有请求都需要上述指定的时间来加载。这些请求不应该很耗时,因为它们使用 MySQL 操作加载 CakePHP 生成的页面,耗时不到 3 毫秒(如框架的调试器中所示)。我还在 Windows 7 计算机上使用 XAMPP(因此是 Apache Webserver)。
感谢您的回答,我相信这篇文章对其他人也有用。
I am currently working on a project and testing it on my localhost.
The thing I am worried about is that pages are loaded quite slow (500-700ms and not less). I thought localhost would load faster than any other web page (as it resides on my local machine). Therefore, if these are the load times on localhost, would they be significantly bigger when moving my site on a remote server?
As technical details, I am developing on CakePHP framework and have several AJAX requests, all taking the above specified time to load. The requests shouldn't be time-consuming, as they load a CakePHP-generated pages with MySQL operations which take less than 3ms (as shown in the framework's debugger). I am also using XAMPP (therefore Apache webserver) on a Windows 7 machine.
Thank you for your answers and I believe this post would be useful to others as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能会发现加载时间更快 - 您的计算机不太可能像真正的服务器一样强大。
就我个人而言,我总是对我的项目实时运行速度有多快感到惊讶 - 但这可能取决于服务器。您应该上传一个快速测试来缓解您的担忧。
You'll probably see faster loading time - it's unlikely your computer is as powerful as a real server.
Personally, I'm always surprised by how much faster my projects run live - but this could depend on the server. You should upload a quick test to ease your worry.
另请记住,测试时您可能会使用大于 0 的调试设置。当大于 0 时,您的模型结构不会被缓存,从而导致 cake 在每个请求时重新加载它们
Also bear in mind that when testing you will probably use debug set to greater than 0. When greater then 0 your model structures are not cached making cake reload them on every request
如果您说 MySQL 很快,但速度下降纯粹是 PHP 造成的,那么启用 APC 扩展可能会有所帮助。 APC 缓存 PHP 解析器的输出并进行一些其他优化。通常它可以节省很多。
但一般来说,您需要进行分析。使用 XDebug 获取分析信息并使用 WinCacheGrind 读出速度缓慢的位置。
If you're saying MySQL is fast, but the slowdown is purely in PHP, enabling the APC extension may help. APC caches the output of the PHP parser and does a few other optimizations. Often it can save a ton.
But in general, you'll want to do profiling. Use XDebug to get profiling information and use WinCacheGrind to read out where things are slow.