adding ob_start() at beginning of index.php might speed up Drupal.
At least one of my servers says 4000ms page execution when no ob_start() & 400ms when it is turned on.

Comments

yngens’s picture

Version: x.y.z » 5.x-dev

on http://phplens.com/lens/php-book/optimizing-debugging-php.php it is said that

Finally, the HTML sent to a web client can be compressed. This is enabled by placing the following code at the beginning of your PHP script:


ob_start("ob_gzhandler");

:
:

If your HTML is highly compressible, it is possible to reduce the size of your HTML file by 50-80%, reducing network bandwidth requirements and latencies. The downside is that you need to have some CPU power to spare for compression.

Is it the same with what doq proposes? should it be just ob_start() or ob_start("ob_gzhandler")?

kbahey’s picture

I can't reproduce your test results, so I can't say it is a general improvement. Must be something specific to your setup.

I ran ab (Apache benchmark) using

ab -c 10 -n 1000 http://something.example.com/

Before adding ob_start() to the index.php

Document Path:          /
Document Length:        4850 bytes

Concurrency Level:      10
Time taken for tests:   32.139774 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      5401000 bytes
HTML transferred:       4850000 bytes
Requests per second:    31.11 [#/sec] (mean)
Time per request:       321.398 [ms] (mean)
Time per request:       32.140 [ms] (mean, across all concurrent requests)
Transfer rate:          164.10 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   43  51.8     31     469
Processing:    32  275 376.0    250    5485
Waiting:        0  162 379.4    124    5360
Total:         63  319 377.1    313    5549

Percentage of the requests served within a certain time (ms)
  50%    313
  66%    316
  75%    317
  80%    317
  90%    319
  95%    343
  98%    564
  99%   2117
 100%   5549 (longest request)

After adding the ob_start() to index.php

Document Path:          /
Document Length:        4850 bytes

Concurrency Level:      10
Time taken for tests:   32.732050 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      5401000 bytes
HTML transferred:       4850000 bytes
Requests per second:    30.55 [#/sec] (mean)
Time per request:       327.321 [ms] (mean)
Time per request:       32.732 [ms] (mean, across all concurrent requests)
Transfer rate:          161.13 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   15  31.0      0     149
Processing:    29  298 1594.2    104   19046
Waiting:       29  282 1595.1    103   19046
Total:         29  313 1594.5    104   19046

Percentage of the requests served within a certain time (ms)
  50%    104
  66%    189
  75%    253
  80%    313
  90%    377
  95%    380
  98%    586
  99%   2523
 100%  19046 (longest request)

As you can see, the latter seems slower by a tiny bit.

marcingy’s picture

Status: Active » Closed (fixed)