views:

92

answers:

1

I have a site where a page takes 10 seconds to load with firefox, and a further 10 seconds to load the images. It's a php page running on apache. The Images are just static images.

It runs beautifully on chrome.... instant loading.

googling for the answer has pointed me towards a possible issue with keep alive and the lack of content length confusing firefox, and indeed, it appears that content length isn't being set by the server on either the static or non static content, but disabling keep alive on the server doubles the load time!

Some sites have suggested disabling keep alive on the browser, but I'm reluctant to recommend that to everyone that views the page! Am I perhaps barking up the wrong tree?

browser is firefox 3.6.8 on Lucid Lynx. server is Apache 2.2.11.

apache.conf is apended... I think it's the one that comes out of the box, although I reduced the KeepAlive timeout to 3 in a vain attempt to try and get the page to load.

Am I barking up the wrong tree?

ServerRoot "/etc/apache2"

LockFile /var/lock/apache2/accept.lock
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 3
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>
<IfModule mpm_worker_module>
    StartServers          2
    MaxClients          150
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadsPerChild      25
    MaxRequestsPerChild   0
</IfModule>
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
AccessFileName .htaccess
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
</Files>
DefaultType text/plain
HostnameLookups Off
ErrorLog /var/log/apache2/error.log
LogLevel warn
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
Include /etc/apache2/httpd.conf
Include /etc/apache2/ports.conf
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
CustomLog /var/log/apache2/other_vhosts_access.log vhost_combined
Include /etc/apache2/conf.d/
Include /etc/apache2/sites-enabled/
A: 

Don't disable keep-alive. It makes that one connection can be used to get multiple pages (or images, or .js files, or .css files, etc.), which reduces page load time significantly.

Just make sure your scripts add Content-Length headers and all will be fine.

mvds
I'll have a look at the php script, but Shouldn't apache be adding the content length to static files? Come to think of it, I've never had to manually add content length to a php file either...
ohp
Apache should do that, yes. But just start with fixing things that are easy. The content-length issue can cause trouble with chunked transfers, https, and all kinds of weirdness I've seen over the years. Just do it by the spec: specify a Content-Length.
mvds
am reading the wc3 spec at http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html which says that the content length should be set when the content length is known prior to transmission. If the content is dynamically generated, what's the best practice for determining the value?And how can I get apache to set the content length for a static graphic file?
ohp
don't know about apache, I think it will set content-length when keepalive is on. Getting content-length from a php script, in general (as an example) is done by calling ob_get_length() after you're done generating output. (yes you must use output buffering in that case) In some cases you may know content-length in advance.
mvds
OK, I have the same problem with static files, and the server is serving content-length headers, so I'm going to shelve this line of enquiry for the time being. I've posted relevant data on the test site.
ohp
You probably have static and dynamic pages on the same host, and therefore within the same connection, and the dynamic ones mess up things for the static ones. Just add that content-length header.
mvds
see the test site. It's purely static.
ohp
Oh that link. Sorry, can't reproduce any problem with that, it just works!
mvds
That's why I reckon it must be s specific issue with my firefox install.
ohp