Welcome to Centmin Mod Community
Register Now

PHP-FPM session.serialize_handler

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Matt, May 27, 2014.

  1. Matt

    Matt Moderator Staff Member

    819
    360
    63
    May 25, 2014
    Rotherham, UK
    Ratings:
    +549
    Local Time:
    12:36 AM
    1.5.15
    MariaDB 10.2
    As igbinary is installed as part of the php-fpm setup with centminmod, is there any reason why it's not used as the session.serialize_handler for PHP?

    upload_2014-5-26_19-4-37.png

    I always use this where igbinary is available, and even better when Memcached is there to use for the session handler.

    Code:
    sed -i 's/session.save_handler = files/session.save_handler = memcached/g' /usr/local/lib/php.ini
    sed -i 's/;session.save_path = \"\/tmp\"/session.save_path = \"127.0.0.1:11211\"/g' /usr/local/lib/php.ini
    sed -i 's/session.serialize_handler = php/session.serialize_handler = igbinary/g' /usr/local/lib/php.ini
     
    • Like Like x 1
  2. eva2000

    eva2000 Administrator Staff Member

    39,828
    8,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,526
    Local Time:
    9:36 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    @Matt where you are determining the usage ? AFAIK, default igbinary install does use the session.serialize_handler if you look at the code on Github at line 68 https://github.com/centminmod/centminmod/blob/123.07beta20/inc/igbinary.inc#L68

    Code:
    [igbinary]
    extension=igbinary.so
    ;Use igbinary as session serializer
    session.serialize_handler=igbinary
    
    ;Enable or disable compacting of duplicate strings
    igbinary.compact_strings=On
    
    ;Use igbinary as serializer in APC cache
    ;apc.serializer=igbinary
     
    Last edited: May 27, 2014
  3. eva2000

    eva2000 Administrator Staff Member

    39,828
    8,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,526
    Local Time:
    9:36 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
  4. Matt

    Matt Moderator Staff Member

    819
    360
    63
    May 25, 2014
    Rotherham, UK
    Ratings:
    +549
    Local Time:
    12:36 AM
    1.5.15
    MariaDB 10.2
    From the default settings in php.ini

    This is the alert from the last update I did last night, where it reverted back to settings:

    Code:
    checking updated php.ini compared to old /usr/local/lib/php.ini-oldversion_250514-194519
    please note the following differences:
    if APC, Xcache, Memcache, Suhosin or FFMPEG Extensions are listed please re-install them
    
    --------------------------------------------------------------------------------------------
    375c375
    < max_execution_time = 60
    ---
    > max_execution_time = 300
    396c396
    < memory_limit = 128M
    ---
    > memory_limit = 256M
    913c913
    < date.timezone = UTC
    ---
    > date.timezone = Europe/London
    1361c1361
    < session.save_handler = files
    ---
    > session.save_handler = memcached
    1390c1390
    < ;session.save_path = "/tmp"
    ---
    > session.save_path = "127.0.0.1:11211"
    1440c1440
    < session.serialize_handler = php
    ---
    > session.serialize_handler = igbinary
    I didn't realise the included inc file over wrote the values in the php.ini file :oops:

    Code:
    ; Handler used to serialize data.  php is the standard serializer of PHP.
    ; http://php.net/session.serialize-handler
    session.serialize_handler = php
    upload_2014-5-26_19-29-35.png
     
  5. eva2000

    eva2000 Administrator Staff Member

    39,828
    8,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,526
    Local Time:
    9:36 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Yeah dynamically overwrite values so I can anticipate end users making PHP and php.ini related changes :D
     
    • Like Like x 1
  6. Matt

    Matt Moderator Staff Member

    819
    360
    63
    May 25, 2014
    Rotherham, UK
    Ratings:
    +549
    Local Time:
    12:36 AM
    1.5.15
    MariaDB 10.2
    It's just something I always changed manually when I was on a Cpanel server, so going to this makes it easier then (y)
     
  7. eva2000

    eva2000 Administrator Staff Member

    39,828
    8,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,526
    Local Time:
    9:36 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Centmin Mod evolved the way it did, as I want to save time too :D

    and FYI, the igbinary settings has it's own ini outside of php.ini so no need to add to php.ini

    so you can probably add your own custom settings to inc/igbinary.inc before actual install at lines 65 to 74 https://github.com/centminmod/centminmod/blob/123.07beta20/inc/igbinary.inc

    Code:
    ls -lah /etc/centminmod/php.d/
    total 32K
    drwxr-xr-x 2 root root 4.0K May 24 03:18 .
    drwxr-xr-x 3 root root 4.0K May 24 01:58 ..
    -rw-r--r-- 1 root root   19 May 24 03:18 geoip.ini
    -rw-r--r-- 1 root root  252 May 24 03:18 igbinary.ini
    -rw-r--r-- 1 root root   21 May 24 03:18 imagick.ini
    -rw-r--r-- 1 root root  115 May 24 03:18 memcached.ini
    -rw-r--r-- 1 root root   78 May 24 03:18 memcache.ini
    -rw-r--r-- 1 root root  382 May 24 03:23 zendopcache.ini
     
    Last edited: May 27, 2014
  8. rdan

    rdan Well-Known Member

    4,525
    1,085
    113
    May 25, 2014
    Ratings:
    +1,583
    Local Time:
    7:36 AM
    Mainline
    10.2
    So the performance is best when we use session.serialize_handler = igbinary compare to session.serialize_handler = php?
     
  9. eva2000

    eva2000 Administrator Staff Member

    39,828
    8,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,526
    Local Time:
    9:36 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    It was with APC Cache combination. Haven't tested or seen benchmarks for Zend Opcache and igbinary based session.serialize_handler
     
    • Like Like x 1
  10. eva2000

    eva2000 Administrator Staff Member

    39,828
    8,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +13,526
    Local Time:
    9:36 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    @Matt ever since PHP 7.3 came out, been curious who does PHP 7.3 default session serialize_handler=php compare to serialize_handler=igbinary. So ran igbinary source codes included run-bench.php benchmark script to compare on my Intel Xeon Core i7 4790K 4C/8T dedicated server running Centmin Mod 123.09beta01 and these are the results.

    Code (Text):
    php -v
    PHP 7.3.1 (cli) (built: Jan 13 2019 04:27:23) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies
        with Zend OPcache v7.3.1, Copyright (c) 1999-2018, by Zend Technologies
    

    Code (Text):
    php --ri igbinary
    
    igbinary
    
    igbinary support => enabled
    igbinary version => 2.0.8
    igbinary APC serializer ABI => no
    igbinary session support => yes
    
    Directive => Local Value => Master Value
    igbinary.compact_strings => On => On
    

    Code (Text):
    lscpu
    Architecture:          x86_64
    CPU op-mode(s):        32-bit, 64-bit
    Byte Order:            Little Endian
    CPU(s):                8
    On-line CPU(s) list:   0-7
    Thread(s) per core:    2
    Core(s) per socket:    4
    Socket(s):             1
    NUMA node(s):          1
    Vendor ID:             GenuineIntel
    CPU family:            6
    Model:                 60
    Model name:            Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
    Stepping:              3
    CPU MHz:               4199.462
    CPU max MHz:           4400.0000
    CPU min MHz:           800.0000
    BogoMIPS:              7981.77
    Virtualization:        VT-x
    L1d cache:             32K
    L1i cache:             32K
    L2 cache:              256K
    L3 cache:              8192K
    NUMA node0 CPU(s):     0-7
    Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm epb ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts spec_ctrl intel_stibp flush_l1d
    

    default session.serialize_handler=php
    Code (Text):
    ------------------------------------------------------------
    PHP 7.3.1 igbinary session.serialize_handler=php benchmark
    Available serializers => php, igbinary
    session.serialize_handler => php => php
    ------------------------------------------------------------
    Serialize-array-of-array-and-unserialize-it  2.03s
    Serialize-large-strings-array                7.65s
    Serialize-object-array                       7.14s
    Serialize-scalar-array                       6.86s
    Serialize-scalar-int                         8.44s
    Unserialize-large-strings-array              6.48s
    Unserialize-object-array                     4.21s
    Unserialize-scalar-array                     2.77s
    Unserialize-scalar-int                       6.05s
    ------------------------------------------------------------
    

    igbinary session.serialize_handler=igbinary
    Code (Text):
    ------------------------------------------------------------
    PHP 7.3.1 igbinary session.serialize_handler=igbinary benchmark
    Available serializers => php, igbinary
    session.serialize_handler => igbinary => igbinary
    ------------------------------------------------------------
    Serialize-array-of-array-and-unserialize-it  1.99s
    Serialize-large-strings-array                7.65s
    Serialize-object-array                       6.92s
    Serialize-scalar-array                       6.84s
    Serialize-scalar-int                         8.44s
    Unserialize-large-strings-array              6.46s
    Unserialize-object-array                     4.27s
    Unserialize-scalar-array                     2.69s
    Unserialize-scalar-int                       5.96s
    ------------------------------------------------------------
    

    Very very close with igbinary just edging default PHP 7.3.1 session serialize_handler=php. Though not all php web applications are compatible with using igbinary for session.serialize_handler=igbinary and can get some interesting issues sometimes which require switching back to default session serialize_handler=php.

    More benchmarks

    igbinary session.serialize_handler=php
    Code (Text):
    ------------------------------------------------------------
    PHP 7.2.14 igbinary session.serialize_handler=php benchmark
    Available serializers => php, igbinary
    session.serialize_handler => php => php
    ------------------------------------------------------------
    test_deep_arr_both.php  igbinary_serialize    time:  1.9096140861511
    test_deep_arr_both.php  igbinary_unserialize  time:  0.60178995132446
    test_deep_arr_both.php  json_decode           time:  2.5765709877014
    test_deep_arr_both.php  json_encode           time:  1.5915360450745
    test_deep_arr_both.php  serialize             time:  1.1209659576416
    test_deep_arr_both.php  unserialize           time:  1.9736258983612
    test_deep_arr_int.php   igbinary_serialize    time:  0.52691102027893
    test_deep_arr_int.php   igbinary_unserialize  time:  0.62034010887146
    test_deep_arr_int.php   json_decode           time:  0.89660406112671
    test_deep_arr_int.php   json_encode           time:  0.22521495819092
    test_deep_arr_int.php   serialize             time:  0.47014594078064
    test_deep_arr_int.php   unserialize           time:  1.4596109390259
    test_deep_arr_str.php   igbinary_serialize    time:  1.6608810424805
    test_deep_arr_str.php   igbinary_unserialize  time:  0.75688910484314
    test_deep_arr_str.php   json_decode           time:  2.4609520435333
    test_deep_arr_str.php   json_encode           time:  1.2287170886993
    test_deep_arr_str.php   serialize             time:  0.89100909233093
    test_deep_arr_str.php   unserialize           time:  1.5922608375549
    test_deep_object.php    igbinary_serialize    time:  0.068819999694824
    test_deep_object.php    igbinary_unserialize  time:  0.03569221496582
    test_deep_object.php    json_decode           time:  0.35190010070801
    test_deep_object.php    json_encode           time:  0.13189816474915
    test_deep_object.php    serialize             time:  0.017965078353882
    test_deep_object.php    unserialize           time:  0.060574054718018
    test_number.php         igbinary_serialize    time:  0.011296987533569
    test_number.php         igbinary_unserialize  time:  0.01245903968811
    test_number.php         json_decode           time:  0.07331109046936
    test_number.php         json_encode           time:  0.032515048980713
    test_number.php         serialize             time:  0.038239002227783
    test_number.php         unserialize           time:  0.14133501052856
    test_object.php         igbinary_serialize    time:  0.003122091293335
    test_object.php         igbinary_unserialize  time:  0.002763032913208
    test_object.php         json_decode           time:  0.029021978378296
    test_object.php         json_encode           time:  0.010985851287842
    test_object.php         serialize             time:  0.0016341209411621
    test_object.php         unserialize           time:  0.0049788951873779
    test_string.php         igbinary_serialize    time:  0.074466943740845
    test_string.php         igbinary_unserialize  time:  0.032006978988647
    test_string.php         json_decode           time:  0.52378511428833
    test_string.php         json_encode           time:  0.22912406921387
    test_string.php         serialize             time:  0.033659934997559
    test_string.php         unserialize           time:  0.091597080230713
    ------------------------------------------------------------
    

    igbinary session.serialize_handler=igbinary
    Code (Text):
    ------------------------------------------------------------
    PHP 7.2.14 igbinary session.serialize_handler=igbinary benchmark
    Available serializers => php, igbinary
    session.serialize_handler => igbinary => igbinary
    ------------------------------------------------------------
    test_deep_arr_both.php  igbinary_serialize    time:  1.7937061786652
    test_deep_arr_both.php  igbinary_unserialize  time:  0.58841896057129
    test_deep_arr_both.php  json_decode           time:  2.4394109249115
    test_deep_arr_both.php  json_encode           time:  1.3461389541626
    test_deep_arr_both.php  serialize             time:  1.0307521820068
    test_deep_arr_both.php  unserialize           time:  1.8233361244202
    test_deep_arr_int.php   igbinary_serialize    time:  0.47547101974487
    test_deep_arr_int.php   igbinary_unserialize  time:  0.59472608566284
    test_deep_arr_int.php   json_decode           time:  0.7866690158844
    test_deep_arr_int.php   json_encode           time:  0.23991084098816
    test_deep_arr_int.php   serialize             time:  0.41093111038208
    test_deep_arr_int.php   unserialize           time:  1.4618530273438
    test_deep_arr_str.php   igbinary_serialize    time:  1.6195290088654
    test_deep_arr_str.php   igbinary_unserialize  time:  0.68997001647949
    test_deep_arr_str.php   json_decode           time:  2.3808541297913
    test_deep_arr_str.php   json_encode           time:  1.3016731739044
    test_deep_arr_str.php   serialize             time:  0.83341503143311
    test_deep_arr_str.php   unserialize           time:  1.5501270294189
    test_deep_object.php    igbinary_serialize    time:  0.065461874008179
    test_deep_object.php    igbinary_unserialize  time:  0.035401821136475
    test_deep_object.php    json_decode           time:  0.30901408195496
    test_deep_object.php    json_encode           time:  0.12088990211487
    test_deep_object.php    serialize             time:  0.028589963912964
    test_deep_object.php    unserialize           time:  0.054042100906372
    test_number.php         igbinary_serialize    time:  0.010663986206055
    test_number.php         igbinary_unserialize  time:  0.011641979217529
    test_number.php         json_decode           time:  0.070590972900391
    test_number.php         json_encode           time:  0.016229152679443
    test_number.php         serialize             time:  0.026972055435181
    test_number.php         unserialize           time:  0.065106868743896
    test_object.php         igbinary_serialize    time:  0.0037839412689209
    test_object.php         igbinary_unserialize  time:  0.0027129650115967
    test_object.php         json_decode           time:  0.029259920120239
    test_object.php         json_encode           time:  0.011251926422119
    test_object.php         serialize             time:  0.0015568733215332
    test_object.php         unserialize           time:  0.0048959255218506
    test_string.php         igbinary_serialize    time:  0.065610885620117
    test_string.php         igbinary_unserialize  time:  0.034590005874634
    test_string.php         json_decode           time:  0.52561616897583
    test_string.php         json_encode           time:  0.24568819999695
    test_string.php         serialize             time:  0.037933826446533
    test_string.php         unserialize           time:  0.077128171920776
    ------------------------------------------------------------
    


    and

    encode
    Code (Text):
    serialize() [strings]: Size: 105 bytes, 0.027251958847046 time to encode
    json_encode() [strings]: Size: 67 bytes, 0.031628847122192 time to encode
    igbinary_serialize() [strings]: Size: 64 bytes, 0.060793161392212 time to encode
    ============================================================
    serialize() [integers]: Size: 121 bytes, 0.048028945922852 time to encode
    json_encode() [integers]: Size: 34 bytes, 0.04364013671875 time to encode
    igbinary_serialize() [integers]: Size: 58 bytes, 0.054417133331299 time to encode
    ============================================================
    serialize() [booleans]: Size: 62 bytes, 0.023934125900269 time to encode
    json_encode() [booleans]: Size: 39 bytes, 0.011503934860229 time to encode
    igbinary_serialize() [booleans]: Size: 27 bytes, 0.040909051895142 time to encode
    ============================================================
    serialize() [floats]: Size: 164 bytes, 0.56924080848694 time to encode
    json_encode() [floats]: Size: 77 bytes, 0.57201910018921 time to encode
    igbinary_serialize() [floats]: Size: 142 bytes, 0.075693130493164 time to encode
    ============================================================
    serialize() [mixed]: Size: 76 bytes, 0.14012002944946 time to encode
    json_encode() [mixed]: Size: 54 bytes, 0.14308500289917 time to encode
    igbinary_serialize() [mixed]: Size: 50 bytes, 0.081045866012573 time to encode
    ============================================================
    serialize() [objects]: Size: 326 bytes, 0.12120008468628 time to encode
    json_encode() [objects]: Size: 148 bytes, 0.10110116004944 time to encode
    igbinary_serialize() [objects]: Size: 177 bytes, 0.13255405426025 time to encode
    ============================================================
    serialize() [all]: Size: 920 bytes, 1.053689956665 time to encode
    json_encode() [all]: Size: 462 bytes, 0.91429996490479 time to encode
    igbinary_serialize() [all]: Size: 478 bytes, 0.34024000167847 time to encode
    ============================================================
    

    decode
    Code (Text):
    unserialize() [strings]: 0.11395502090454 time to decode
    json_decode() [strings]: 0.15414381027222 time to decode
    igbinary_unserialize() [strings]: 0.047164916992188 time to decode
    ============================================================
    unserialize() [integers]: 0.20378708839417 time to decode
    json_decode() [integers]: 0.14034795761108 time to decode
    igbinary_unserialize() [integers]: 0.04066014289856 time to decode
    ============================================================
    unserialize() [booleans]: 0.10748314857483 time to decode
    json_decode() [booleans]: 0.07295298576355 time to decode
    igbinary_unserialize() [booleans]: 0.025300979614258 time to decode
    ============================================================
    unserialize() [floats]: 0.2080409526825 time to decode
    json_decode() [floats]: 0.18522691726685 time to decode
    igbinary_unserialize() [floats]: 0.039689064025879 time to decode
    ============================================================
    unserialize() [mixed]: 0.089251041412354 time to decode
    json_decode() [mixed]: 0.20646619796753 time to decode
    igbinary_unserialize() [mixed]: 0.074903964996338 time to decode
    ============================================================
    unserialize() [objects]: 0.45544195175171 time to decode
    json_decode() [objects]: 0.4108989238739 time to decode
    igbinary_unserialize() [objects]: 0.16691780090332 time to decode
    ============================================================
    unserialize() [all]: 1.2127568721771 time to decode
    json_decode() [all]: 1.1189770698547 time to decode
    igbinary_unserialize() [all]: 0.3771960735321 time to decode
    ============================================================
    
     
    • Like Like x 1
..