TTFB

Hi community, we have a really bad problem with or TTFB in our ecommerce http://solohombre.es
All page speed webs tell us the same. Almost 5 seconds to TTFB

I’m the solohombre’s web consultant, our developers are prosolution.es

You can see here the drama http://www.webpagetest.org/result/160423_NQ_EJ4/1/details/

We have a fast server, our developers are great professionals and we are lost what to do. If we minify *.js, page loose functions like mega menu… We could combine/minify *.css

I copy our .htaccess file at the end of this message, before i want to comment also a DNS analysis in pingdom. A strange thing is on SOA, is it important?

SOA
Could not find reverse address for 74.125.192.27 (27.192.125.74.in-addr.arpa.).
Could not find reverse address for 2607:f8b0:400d:c00:0:0:0:1b (b.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.c.0.d.0.0.4.0.b.8.f.7.0.6.2.ip6.arpa.).

In Results on webpagestest i see on Response: Expires: Thu, 19 Nov 1981 08:52:00 GMT

Is it a huge error?

I insist, i’m web consultant and our developers are prosolutions.es an i’m helping them to resolve this … drama, big drama.

Here the .htaccess

Thanks!

AddType text/cache-manifest .appcache
##################################
####### COMPRESION #######
##################################
php_flag zlib.output_compression On
php_value zlib.output_compression_level 9

AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript


mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript
mod_gzip_item_include mime ^application/javascript
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.gzip.


ExpiresActive On
ExpiresDefault A300
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A3600
ExpiresByType text/css A3600
ExpiresByType image/gif A604800
ExpiresByType image/png A604800
ExpiresByType image/jpeg A604800
ExpiresByType text/plain A300
ExpiresByType application/x-shockwave-flash A604800
ExpiresByType video/x-flv A604800
ExpiresByType application/pdf A604800
ExpiresByType text/html A300

Header set Cache-Control "max-age=29030400"
<filesMatch ".(js|css|swf)$">
	Header set Cache-Control "max-age=604800"
</filesMatch>

<filesMatch ".(html|htm|txt)$">
	Header set Cache-Control "max-age=2700"
</filesMatch>
# BEGIN Browser Cache Header append Vary User-Agent env=!dont-vary AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json # DEFLATE by extension AddOutputFilter DEFLATE js css htm html xml ############################################ ## uncomment these lines for CGI mode ## make sure to specify the correct cgi php binary file name ## it might be /cgi-bin/php-cgi

Action php5-cgi /cgi-bin/php5-cgi

AddHandler php5-cgi .php

############################################

GoDaddy specific options

Options -MultiViews

you might also need to add this line to php.ini

cgi.fix_pathinfo = 1

if it still doesn’t work, rename php.ini to php5.ini

############################################

this line is specific for 1and1 hosting

#AddType x-mapp-php5 .php
#AddHandler x-mapp-php5 .php

############################################

default index file

DirectoryIndex index.php

############################################

adjust memory limit

php_value memory_limit 64M

php_value memory_limit 256M
php_value max_execution_time 18000

############################################

disable magic quotes for php request vars

php_flag magic_quotes_gpc off

############################################

disable automatic session start

before autoload was initialized

php_flag session.auto_start off

############################################

enable resulting html compression

#php_flag zlib.output_compression on

###########################################

disable user agent verification to not break multiple image upload

php_flag suhosin.session.cryptua off

###########################################

turn off compatibility with PHP4 when dealing with objects

php_flag zend.ze1_compatibility_mode Off
########################################### # disable POST processing to not break multiple image upload
SecFilterEngine Off
SecFilterScanPOST Off

############################################

enable apache served files compression ## Best Practices for Speeding Up Your Web Site - Yahoo Developer Network

# Insert filter on all content
###SetOutputFilter DEFLATE
# Insert filter on selected content types only
#AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript

# Netscape 4.x has some problems...
#BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
#BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
#BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# Don't compress images
#SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
#Header append Vary User-Agent env=!dont-vary

############################################

make HTTPS env vars available for CGI mode

SSLOptions StdEnvVars

Options +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www.solohombre.es [NC]
RewriteRule ^(.*)$ http://solohombre.es/$1 [L,R=301]

############################################

never rewrite for existing files, directories and links

RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

############################################

Prevent character encoding issues from server overrides ## If you still have problems, use the second line instead

AddDefaultCharset Off
#AddDefaultCharset UTF-8

############################################

Add default Expires header

Best Practices for Speeding Up Your Web Site - Yahoo Developer Network

ExpiresDefault "access plus 1 year"

############################################

By default allow all access

Order allow,deny
Allow from all

############################################

If running in cluster environment, uncomment this ## Best Practices for Speeding Up Your Web Site - Yahoo Developer Network

#FileETag none

#SetEnv MAGE_IS_DEVELOPER_MODE “true”

So it’s a magento site then (:

First off, the TTFB is a reflection of how well your site builds up the html skeleton of the page, which requires use of php and the database to build. The majority of the contents of the .htaccess above are working on speeding the transfer of static resources, and will not affect the TTFB.

The obvious misconfiguration I see is
php memory is set to 256MB. Minimum recommnded is 384MB.

After that, you need to tune your server to handle the needs of magento:

  • database. ensure using MySQL 5.6 if possible, but make sure you’re using innodb_file_per_table ( you’ll need to dump / restore - and preferably reinstall MySQL if you’re not ), and that there is plenty of innodb cache available. Use a script like mysql_tuner.sh - freely available on the net - to improve your configuration.
  • php. use the latest version that you can. This depends on the version of magento you’re running, so you need to check. Older versions limit you to PHP 5.3 ( there’s a script to update to support 5.4 ), newer allow 5.5, and Magento2 even newer.
  • php opcache. For old versions use eAccelerator in this setup, newer ones use the built in zend opcode cacher.
  • use of tmpfs filesystems. If you have plenty of memory ( and if not, get more! ), then mount var/cache and var/session in memory. Not only can you make it run faster, but the mount parameters can make it safer too.
  • apache. If you’re using SuPHP, then don’t! For best performance, implement a fpm based infrastructure. If you do this, and are using an old version of PHP, then switch to the APC opcode cacher from eAccelerator.

That should get you started at least…

Steve

Thank you so much and i am so happy about your answer and advice.

I transfer yours advice immediately to our developers. If news are good, i’ll share with you, that i’m almost certain it will.

Thank you again Steve

Álvaro

Magento has profiler built-in to help you debug your TTFB problem.

go ahead and enable it and see what magento is doing behind the scenes

here is a nice tutorial on how to enable and use profiler to optimize magento TTFB

enable slow query reports in your MySQL server - that could be some bad written query slowing your down.

in my experience the problem of huge TTFB in magento is poorly written template files.

for example developers load product models inside catalog product list loops:

[php]<?php foreach($collection as $product){
$product = Mage::getModel(‘catalog/product’)->load($product->getId())

[/php]

i see it all the time on clients websites

go over your templates and make sure php code is optimized and doesn’t contain expensive model loads where it doesn’t supposed to

Thank you so much goivvy. I’m going to study what you say and links you share.

I’ll tell you results!