cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to improve time to first byte

Trying to improve time to first byte

Hello,

I have magento 1.9.3.8 store with several extensions installed (most of them developed by me) running on Ubuntu 16.04 virtual machine with 4 cores and 32GB ram, nginx, php-fpm, memcached.

The page load times vary between 1 and 1.5 seconds, however i noticed the page is being generated in buffer and then sent to the browser. I had an idea to flush that buffer after </head> tag (in 2columns-left.phtml) so it starts downloading css and js while parsing the page body.

Unfortunately i get this error in system.log:

DEBUG (7): HEADERS ALREADY SENT: \<pre>[0] /home/furn3284/public_html/app/code/core/Mage/Core/Controller/Response/Http.php:52

Digging in lib/Zend/Controller/Response/Abstract.php around line 320:

        $ok = headers_sent($file, $line);
        if ($ok && $throw && $this->headersSentThrowsException) {
            #require_once 'Zend/Controller/Response/Exception.php';
            throw new Zend_Controller_Response_Exception('Cannot send headers; headers already sent in ' . $file . ', line ' . $line);
        }

        return !$ok;

i was able to see the headers_sent $file is 2columns-left.php and the line is where i use ob_flush();

 

Is there any option/config setting that i can tell headers to be sent before parsing the page template?

Overall it works very well when flushing. TTFB is improved alot, page loading faster and smooth, just this error message in system.log

 

2 REPLIES

Re: Trying to improve time to first byte

Hi @Miro Igov,

 

I guess changing the abstract class isn't the best approach.

If you want to defer the javascript files maybe you can use this module: https://github.com/bobbyshaw/magento-footer-js

 

Then you can use https://github.com/AOEpeople/Aoe_Profiler to try to find if the problem is a module.

 

Another option could be to use a CDN (or at least a Poor-Man-Cdn).

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: Trying to improve time to first byte

Defer JS is not good idea as the TTFB will still be huge (equal to page parse time). I want to send <head></head> section to users immediately aftrer </head> tag and then continue parsing the rest of the site.

Benefits:

- Google ranks sites with low TTFB better

- JS/CSS is downloaded in parallel with remaining page parsing

 

I think it is pretty enough to wait for HTTP headers hooked from extensions until <head> section is parsed. However magento does not allow this because of the abstract class check executed at end of parsing.