简体   繁体   中英

Slow execution of PHP file using Ubuntu + Apache + PHP5

A file named test.html contains:

hello

It takes a few milliseconds to respond.

A file named test.php contains:

hello

This one takes a few seconds to respond. They're both the same code and contain no actual PHP code. The file extension is the only difference!

I'm loading both via http://localhost/test.html or php

Is there any common snafu in the server settings that I missed? I'm using the standard Ubuntu 11.04, Apache2, PHP5 configuration.

Your help is appreciated... let me know what other details you need.

Well even if there is no actual php code in your php file its getting sent to the php parser by apache because of its extension. This probably slows it by a few miliseconds and on your system might be more.

Like others have pointed out you probably have some module that is taking too much time. But about your original question my answer stands. Even without code your php file is getting parsed by php.

If you want to get an idea what is going on try the following:

sudo -i
stop apache2
. /etc/apache2/envvars
apache2 -k start -X &
strace  -u www-data -tt -ff -o /tmp/strace $(ps -o "-p %p" h -u www-data) &

man strace to find out what it does and don't forget to apache2 -k stop and start apache2 when you are done :) Remember you are all-powerful as root so come out ASAP.

Try adding an .htaccess file and also doing a sudo apt-get install php-apc to see how an Opcode cache works. The next stage is to strart downloading the source and matching this up to what is happening in the system trace. Enjoy.

Even though there's no PHP code, it is being parsed as PHP. The problem could exist with Apache's configuration / installed modules, or possibly if you have a bunch of (or any one problematic) enabled module(s) in PHP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM