我有这样的question几个月前。现在为了隔离问题,我尝试了一种新方法。我将一个空文件放到我的服务器上。
文件名为“foobar.php”。其内容如下:
<?php
echo "hello world";
但是当我尝试进入 example.com/foobar.php 时,我得到了
DNS 203 mseconds
Connect 3.33 seconds
Send 0 miliseconds
Time to First Byte 17.35 seconds
Receive 1 miliseconds Total load time 20.88 seconds
然后我放了另一个名为“foobar.txt”的文件。其内容如下:
hello world<br/>
foobar.txt 的加载时间约为 0.2 秒。
此网站位于共享主机内,因此我无法获得根 Linux 访问权限。我正在尝试找出导致我的网站变慢的原因。
- 当我得到这些结果时,我的站点中有 60 位访问者。他们在事件时发送 AJAX 请求。当它们处于事件状态时,它们几乎每 3 秒发送一次 AJAX 请求。
- 通常我的网站每秒有 5-20 个请求。
- 我的托管服务提供商说没有发生 CPU 过载,通常情况下很低。
- 我向托管公司询问了 Apache 限制。我得到了整个共享服务器的值:
MaxClients 300
MaxRequestsPerChild 4000
ThreadsPerChild 25
- example.com/mybigpage.php 和 example.com/foobar.php 页面几乎同时打开。
- 如果页面有 txt、jpeg 或其他扩展名,它们会立即打开。如果扩展名是 php,则打开速度很慢。
- CakePHP 将 session 文件存储在“/httpdocs/app/tmp/sessions”文件夹中。 session 文件在创建两个小时后被删除。现在该文件夹中有 3653 个文件。最旧的文件创建于 2.5 小时前。
- 在我的配置中,PHP 处理程序是 Apache 模块 mod_php
新编辑: 我和我的托管公司谈过。并告诉他们“foobar.php”将在 20 秒内打开。虽然那个文件根本就没有代码。他们告诉我他们将“foobar.php”放到我们使用同一服务器的其他网站上。我也试过“othersite.com/foobar.php”。它立即打开。但是“mysite.com/foobar.php”几乎在 15 秒内打开。什么会导致这种行为?我们与其他网站使用相同的 PHP 配置,但它们会立即打开。 会不会是因为我的 .htaccess 规则?还是其他?
新编辑2: 我的提供者告诉我服务器内不存在“apd.so”文件。所以看来我不能使用 APD。
我应该找什么来找到瓶颈?
什么会限制我的网站?
附加数据:从 phpinfo,我得到这个:
'./configure' '--prefix=/usr/local/lsws/lsphp5' '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib64' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.dd' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-curl' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-libexpat-dir=/usr/lib64' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-wddx' '--with-kerberos' '--enable-ucd-snmp-hack' '--with-unixODBC=shared,/usr' '--enable-shmop' '--enable-calendar' '--with-libxml-dir=/usr' '--with-mysql' '--with-mysqli' '--with-gd' '--enable-dom' '--disable-dba' '--without-unixODBC' '--enable-xmlreader' '--enable-xmlwriter' '--with-mcrypt' '--enable-mbstring' '--with-litespeed' '--enable-soap' '--with-xsl' '--with-pdo-mysql' '--with-pdo-sqlite' '--enable-sqlite-utf8' '--with-pspell' '--with-sqlite=shared' '--with-xmlrpc' '--with-mhash' '--enable-pdo' '--with-imap' '--with-imap-ssl' '--without-suhosin' '--with-tidy' '--enable-zip' '--enable-inline-optimization' '--enable-gd-native-ttf' '--enable-bcmath'
最佳答案
似乎很明显是 PHP 问题,因为 Apache 提供静态文件没有问题。你试过安装APD来自PECL?
使用像 APD 这样的 PHP 分析器将向您显示瓶颈是否在 PHP 中,如果是的话,它在哪里。例如,您正在使用的框架是否运行缓慢?或者可能只是一个恶意扩展?
引自官方manual :
使用 APD,您只需在入口点添加一条指令:
<?php
apd_set_pprof_trace();
?>
APD 会将分析信息转储到 *apd.dumpdir/pprof_pid.ext*。
然后,pprofp 将使用您的转储文件并告诉您哪些方法正在消耗响应时间:
bash-2.05b$ pprofp -R /tmp/pprof.22141.0
Trace for /home/dan/testapd.php
Total Elapsed Time = 0.00
Total System Time = 0.00
Total User Time = 0.00
Real User System secs/ cumm
%Time (excl/cumm) (excl/cumm) (excl/cumm) Calls call s/call Memory Usage Name
--------------------------------------------------------------------------------------
100.0 0.00 0.00 0.00 0.00 0.00 0.00 1 0.0000 0.0009 0 main
56.9 0.00 0.00 0.00 0.00 0.00 0.00 1 0.0005 0.0005 0 apd_set_pprof_trace
28.0 0.00 0.00 0.00 0.00 0.00 0.00 10 0.0000 0.0000 0 preg_replace
14.3 0.00 0.00 0.00 0.00 0.00 0.00 10 0.0000 0.0000 0 str_replace
如果您在配置文件中没有显示任何延迟,则表明这是系统范围的 PHP 配置问题(可能是恶意扩展或配置错误的扩展)。但我猜这是框架中的东西。
关于php - 空php文件的第一个字节值的长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14002677/