Remove extensions that I don’t use would impact PHP page execution performance

Asked

Viewed 347 times

10

I installed PHP through the Web Platform and it came with several extensions loaded:

php.ini

[ExtensionList]
extension=php_mysqli.dll
extension=php_mbstring.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_curl.dll
extension=php_exif.dll
extension=php_xmlrpc.dll
extension=php_openssl.dll
extension=php_soap.dll
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_imap.dll
extension=php_tidy.dll

Remove extensions that I don’t use would impact PHP page execution performance?

  • I believe they are only used when requested by the script, so "I think" that Naum...

  • 3

    I have a habit of disabling everything I don’t use for a number of other reasons, but the performance won’t change. I would suggest disabling everything that is "left over" from tomorrow or later, when you install something that needs some of them, remember that disabled.

  • Instead of speculating, why not measure performance with present and missing extensions, compare results and come to an objective conclusion?

  • @Matheusmoreira how can I measure performance?

1 answer

11


Although I agree with the comments and the another response from Brittz, there are still extensions that when disabled improve the performance of the server, today it is somewhat unusual but in the past the Shared and VPS servers came as extensions like Xdebug and/or Xhprof enabled.

If you have full control over your server it is preferable to check all extensions that are used to debug and shut them down.

The following tests were carried out on:

  • PHP 5.6 (x86_x64)
  • Windows 8 64bit
  • Apache 2.3.4

Memoriam

I created the following file foo.php and routed via http (http://localhost/foo.php):

<?php

register_shutdown_function(function () {
    echo 'Pico de uso da memória: ', memory_get_peak_usage() / 1024, 'kb', PHP_EOL;
});
  • Result Xdebug disconnected:

    Peak memory usage: 217.15625kb

  • Result Xdebug connected:

    Peak memory usage: 234.6171875kb

At first it seems insignificant, but this is a result with an "empty" file, if using a framework like Laravel will notice the impact

  • Laravel with Xdebug off:

    Peak memory usage: 7312.4921875kb

  • Laravel with Xdebug on:

    Peak memory usage: 8377.90625kb

The peak could have been higher, but this example is the Laravel "clean"

Requests per second

I took the test with the foo.php using the Apachebench

  • With Xdebug off the result was ~3000.63 requests per second, full answer:

    Server Software:        Apache/2.4.3
    Server Hostname:        localhost
    Server Port:            80
    
    Document Path:          /foo.php
    Document Length:        37 bytes
    
    Concurrency Level:      10
    Time taken for tests:   0.333 seconds
    Complete requests:      1000
    Failed requests:        0
    Write errors:           0
    Total transferred:      202000 bytes
    HTML transferred:       37000 bytes
    Requests per second:    3000.63 [#/sec] (mean)
    Time per request:       3.333 [ms] (mean)
    Time per request:       0.333 [ms] (mean, across all concurrent requests)
    Transfer rate:          591.92 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.3      0       2
    Processing:     1    3   5.1      3     112
    Waiting:        0    3   5.0      2     110
    Total:          1    3   5.1      3     112
    
    Percentage of the requests served within a certain time (ms)
      50%      3
      66%      3
      75%      3
      80%      3
      90%      4
      95%      5
      98%      8
      99%     18
     100%    112 (longest request)
    executed: ab -n 1000 -c 10 "http://localhost/foo.php"
    
  • With Xdebug on were ~1978.29 requests per second:

    Server Software:        Apache/2.4.3
    Server Hostname:        localhost
    Server Port:            80
    
    Document Path:          /foo.php
    Document Length:        38 bytes
    
    Concurrency Level:      10
    Time taken for tests:   0.505 seconds
    Complete requests:      1000
    Failed requests:        0
    Write errors:           0
    Total transferred:      203000 bytes
    HTML transferred:       38000 bytes
    Requests per second:    1978.29 [#/sec] (mean)
    Time per request:       5.055 [ms] (mean)
    Time per request:       0.505 [ms] (mean, across all concurrent requests)
    Transfer rate:          392.18 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0    0   0.3      0       3
    Processing:     1    5   4.5      4      64
    Waiting:        1    4   4.5      4      63
    Total:          1    5   4.5      4      64
    
    Percentage of the requests served within a certain time (ms)
      50%      4
      66%      5
      75%      5
      80%      5
      90%      6
      95%      7
      98%     13
      99%     27
     100%     64 (longest request)
    executed: ab -n 1000 -c 10 "http://localhost/foo.php"
    

In short, or practically ~1000 requests less in a second

Note that the tests were done with Xdebug in its minimum settings, if using profile and other things can still consume more.

Extensions that improve performance

Yes there are, no language in the back-end will be able to achieve a good performance of truth unless it is "compiled" and/or uses "Opcode" structure, many server languages have something like this, but PHP has not (had not), at least not enabled by default.

  • PHP 5.4 and older:

    We have the Xcache, it gives a small improvement on the server, as far as tested it can be very useful for heavier frameworks.

    This extension is not maintained by the PHP team, but by the lighttpd team, or you may have to install it manually (and compile).

    However some servers have it installed already, just need to enable, but if not then you will have to compile directly on your server and configure, if you do not have this option then just asking for support. Other than that, she doesn’t need to set up much cacher in php.ini:

    [xcache]
    xcache.cacher="On"
    
  • PHP 5.4:

    In version 5.4 was created the Alternative PHP Cache (APC), however now can only be installed via PECL, it has proven to have good efficiency, however it is complicated to install on production servers.

  • PHP 5.5:

    From the 5.5 we have the Opcache (or Zend Opcache), although it is only available natively in PHP 5.5 it is possible to install in older versions through PECL (5.2, 5.3 and 5.4), of the tests I performed it was the most efficient.

All 3 of these use a structure called Opcode, of course each in its own way, but the use of them still significantly improves the performance of script executions.

Use of memory with Zendopcache script foo.php:

Memory usage peak: 206.4453125kb

It seems insignificant, but if you add up multiple requests and use a heavy framework you will notice a good difference.

See the difference of Laravel:

Memory usage peak: 2308.3203125kb

Remember that without Zendopcache consumption was 7312.4921875kb

  • 2308.3203125 is approximately 2.25mb
  • 7312.4921875 is approximately 7.14mb

That is a saving of 4.89mb, if you make 10 requests at the same time in a second will be a saving of 48.9mb. This helps prevent it from reaching the server’s memory peak.

But keep in mind that it is relative, it is no use to use Opcache and:

  • Write bad scripts
  • Make a bad bank structure
  • Insert multiple images into page, . js and . css without need

Opcache will not perform miracles, you have to take care of these other details too, it is everything relative.

Follows a basic configuration of Opcache (needs to use zend_extension):

[opcache]
zend_extension=php_opcache.dll
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1

If it is Unix-like (Linux, Mac, BSD):

[opcache]
zend_extension=php_opcache.so

Completion

From your list no extension will affect performance, however you may not need the mysqli and Pdo extension at the same time, but hanging up will make no difference if you come to use a third party script that does not use mysqli, but yes Pdo and another script your need mysqli so it will be better to leave both linked.

The imap extension you may not use, but if you are going to add a web-email, like squiremal or roundcube you will need this extension, the other extensions are the minimum to use the basic functions of text, xml, etc.

extension=php_mysqli.dll
extension=php_mbstring.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_curl.dll
extension=php_exif.dll
extension=php_xmlrpc.dll
extension=php_openssl.dll
extension=php_soap.dll
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_imap.dll
extension=php_tidy.dll

I would personally leave all listed above on, except for SOAP (it is a little unusual to use this)

  • SOAP is required for Newrelic, unless mistaken. I remember when I installed the New Relic started to seem in the logs errors with the SOAP, so I had to give that old yum to resolve. ;P

  • @Inkeliz I understand, I didn’t mean unnecessary, I just meant that nowadays is unusual, since we have other types of webservices or the process is done manually :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.