Long Time to First Byte value for an empty php file

trante picture trante · Dec 22, 2012 · Viewed 10.1k times · Source

I had such question some months ago. Now to isolate the problem I tried a new approach. I put an empty file to my server.

File name is "foobar.php". Its content is as follows:

<?php
echo "hello world";

But when I try to enter to example.com/foobar.php, I get

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

Then I put another file called "foobar.txt". Its content is as follows:

hello world<br/>

Loading time of foobar.txt is approximeately 0.2 seconds.

This website is inside a shared hosting so I can't get a root Linux access. I'm trying to find out what makes my site slow.

  • When I get these results I have 60 visitors in my site. And they send AJAX requests when they are active. When they are active they send an AJAX request nearly every 3 seconds.
  • Generally my website has 5-20 requests per second.
  • My hosting provider says that there occurs no CPU overload, it is very low generally.
  • I asked hosting company for Apache limits. I get this values for the whole shared server:

MaxClients 300
MaxRequestsPerChild 4000
ThreadsPerChild 25

  • example.com/mybigpage.php and example.com/foobar.php pages are opened nearly at the same time.
  • If page has txt, jpeg or other extensions they are opened instantly. If extension is php it opens very slow.
  • CakePHP stores session files inside "/httpdocs/app/tmp/sessions" folder. Session files are deleted after two hours of creation. Now there is 3653 files inside that folder. Oldest file is created 2,5 hours ago.
  • In my configuration, PHP handler is Apache module mod_php

New Edit: I talked with my hosting company. And told them that "foobar.php" is opened nearly in 20 seconds. Although that file has no code at all. They told me that they put "foobar.php" to other websites that we use same server. I also tried "othersite.com/foobar.php". It opened instantly. But "mysite.com/foobar.php" opened nearly in 15 seconds. What would make this behaviour? We use same PHP configuration with other sites, but they open instantly.. Can it be because of my .htaccess rules? Or other thing?

New Edit2: My provider told me that there exists no "apd.so" file inside the server. So it seems like I can't use APD.

What should I look for to find the bottleneck?
What would limit my site?


Additional data: from the phpinfo, I get this:

'./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'

Answer

mjk picture mjk · Dec 26, 2012

Seems clear to be a PHP problem, since Apache has no problem serving static files. Have you tried installing APD from PECL?

Using a PHP profiler like APD will show you whether the bottleneck is in PHP and, if so, where it is. For example, is the slowness in the framework that you're using? Or perhaps just a rogue extension?

Paraphrasing from the official manual:

With APD, you just add an instruction at the entry point:

<?php
apd_set_pprof_trace();
?>

APD will dump profiling information to *apd.dumpdir/pprof_pid.ext*.

Then, pprofp will consume your dump files and tell you what methods are chewing up the response time:

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

If none of the delay you see shows up in the profile, it would suggest it's a systemwide PHP configuration problem (perhaps a rogue or misconfigured extension). But I would guess it's something in the framework.