php - css 和 JS 文件下载时间过长

标签 php apache cakephp

我在 linux 服务器上有一个用 cakephp 编写的网站。我的 css 和 js 文件下载速度极慢。例如,这是加载我的主页时 chrome 中的网络选项卡:

enter image description here

如您所见,我的一个 css 文件下载了 59 秒!重要的是要注意它并不总是相同的 css 文件。有时是它的 JS 文件,有时是其他 css,但它们必须在页面的其他内容显示之前下载,因此它们会阻止页面加载。由于等待那个文件下载,网站有 59 秒没有显示。

我检查了我的服务器,它的负载非常低,CPU 运行在 10% 上,并且使用的 ram 不到 20%。它是一个具有以下 prefork 设置的 apache 服务器:

StartServers       10
MinSpareServers    10
MaxSpareServers    20
ServerLimit        256
MaxClients         256
MaxRequestsPerChild  10000

这个提到的缓慢下载时间发生在网站上可能同时有 3-4 个用户时。我的应用程序在带有 appdynamics 的 APM 下,那里没有显示任何可疑内容。我用服务器管理员检查了 php.ini 文件,那里的一切似乎都很好。我可以使用哪些其他软件来查找此问题的根源? apache 日志中也没有太多信息。

如有任何建议,我们将不胜感激

编辑:

我将所有 Assets 移至 webroot,并在使用同一服务器的另一个域上获得了这些结果:

enter image description here

如您所见,这次它的 jquery 文件下载了 27 秒。它存储在 app/webroot

最佳答案

Ill take a look at serving assets from webroot

始终将公共(public) Assets 放在 webroot 中。

From the book (强调):

It’s a well known fact that serving assets through PHP is guaranteed to be slower than serving those assets without invoking PHP. And while the core team has taken steps to make plugin and theme asset serving as fast as possible, there may be situations where more performance is required. In these situations it’s recommended that you either symlink or copy out plugin/theme assets to directories in app/webroot with paths matching those used by CakePHP.

  • app/Plugin/DebugKit/webroot/js/my_file.js becomes app/webroot/debug_kit/js/my_file.js
  • app/View/Themed/Navy/webroot/css/navy.css becomes app/webroot/theme/Navy/css/navy.css

根据许多因素,“较慢”可能介于几乎不明显和几乎不可用之间。

此建议不是特定于版本的,并且几乎始终适用。为了加快 Assets 加载速度,让网络服务器为您处理它们。

关于php - css 和 JS 文件下载时间过长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32717415/

相关文章:

cakephp - 从 Cake 1.3 迁移到 2.0 及更高版本 - 迁移现有的,还是仅用于新的?

php - 适合论坛的 MVC 结构

php - 如何将csv文件导入mysql数据库,id自动递增到数据库表中。id字段不在文件中,只在表中

cakephp - 如何获取关联表的属性?

apache - mod_proxy 中的 no-jk 等效项

php - UTF-8贯穿始终

mysql - 如何在cakephp中查找最新的记录?

PHP 将节点添加到现有的 xml 文件并保存

javascript - 使用 php 和 jquery 进行 AJAX 表单提交

java - Apache HttpClient UrlEncodedFormEntity 限制大小