FAQ
Hi,

There is a new patch that is changing serialization in GMP:

http://git.php.net/?p=php-src.git;a=commitdiff;h=4218e89f8df4ca3897e3aad595e0c2c9cf4c3aca

It fixes the bug but it also introduces BC break for serialized string
(custom serialization replaced the std object serialization). The problem
is that there can be users (one big user is WordPress) that saves the
serialized into DB which can lead to the difficulties when updating PHP
version.

I think that the new serialized API that I proposed some time ago (
https://wiki.php.net/rfc/internal_serialize_api ) could solve the problem.
I actually just wrote a patch that fixes the same bug and uses a new
serialize API:

https://github.com/bukka/php-src/commit/d3c04d001f3a86409d45a0f268ea4945fa53489b

I also created few benchmarks:
== BEFORE THE FIX ==
O:3:"GMP":1:{s:3:"num";s:2:"42";}
SERIALIZATION: time for 100000 iterations: 0.230430
UNSERIALIZATION: time for 100000 iterations: 0.469807

== AFTER THE FIX ==
C:3:"GMP":15:{s:2:"42";a:0:{}}
SERIALIZATION: time for 100000 iterations: 0.319425
UNSERIALIZATION: time for 100000 iterations: 0.354855

== AFTER MY PATCH (new serialization API) ==
O:3:"GMP":1:{s:3:"num";s:2:"42";}
SERIALIZATION: time for 100000 iterations: 0.195529
UNSERIALIZATION: time for 100000 iterations: 0.241552

As you can see after using a new serialization API, the performance has
improved and mainly the serialized string is the same as the one before the
fix.

If anyone is interested: I also have an initial patch for DateTime (still
need to do quite a few things so it's incomplete but it works fine for
DateTime):
https://github.com/bukka/php-src/compare/date_using_serialize_api#files_bucket

I think that the API patch is ready
https://github.com/bukka/php-src/compare/serialize_internal_api . There are
few extension that could profit from it so I think that it could be a
useful addition...

Any thoughts?

Thanks for reading this long and boring email... :)

Regards

Jakub

Search Discussions

  • Nikita Popov at Oct 30, 2013 at 9:46 pm

    On Wed, Oct 30, 2013 at 10:37 PM, Jakub Zelenka wrote:

    Hi,

    There is a new patch that is changing serialization in GMP:


    http://git.php.net/?p=php-src.git;a=commitdiff;h=4218e89f8df4ca3897e3aad595e0c2c9cf4c3aca

    It fixes the bug but it also introduces BC break for serialized string
    (custom serialization replaced the std object serialization). The problem
    is that there can be users (one big user is WordPress) that saves the
    serialized into DB which can lead to the difficulties when updating PHP
    version.
    As already pointed out on the php-cvs mailing list, this is not a backwards
    compatibility break because it only changes implementation details of a
    feature introduced in master (PHP 5.6). GMP numbers were never serializable
    in any released version of PHP. Ability to serialize was added as part of
    https://wiki.php.net/rfc/operator_overloading_gmp.

    Nikita
  • Jakub Zelenka at Oct 30, 2013 at 10:34 pm

    On Wed, Oct 30, 2013 at 9:46 PM, Nikita Popov wrote:
    As already pointed out on the php-cvs mailing list, this is not a
    backwards compatibility break because it only changes implementation
    details of a feature introduced in master (PHP 5.6). GMP numbers were never
    serializable in any released version of PHP. Ability to serialize was added
    as part of https://wiki.php.net/rfc/operator_overloading_gmp.

    Nikita
    Ok cool no prob

    Just tried some weird cases and think that there is an another problem. The
    self referencing of object don't work. The serialization data (var_hash) is
    not the same (you can't use unserialized references...). Try this:

    $n = gmp_init(42);
    $n->obj = $n;
    var_dump(unserialize(serialize($n)));

    (you will get really cool animation when you run it... :) )

    My patch is not match better as I am getting segfault. :) I will probably
    have to do a bit more testing... :)

    Jakub
  • Jakub Zelenka at Oct 30, 2013 at 10:38 pm

    $n = gmp_init(42);
    $n->obj = $n;
    var_dump(unserialize(serialize($n)));

    (you will get really cool animation when you run it... :) )
    sorry it's working correctly - ignore this... too tired...

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedOct 30, '13 at 9:37p
activeOct 30, '13 at 10:38p
posts4
users2
websitephp.net

2 users in discussion

Jakub Zelenka: 3 posts Nikita Popov: 1 post

People

Translate

site design / logo © 2022 Grokbase