Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float values are being stored as negative #500

Closed
xPaw opened this issue Feb 17, 2022 · 2 comments
Closed

Float values are being stored as negative #500

xPaw opened this issue Feb 17, 2022 · 2 comments

Comments

@xPaw
Copy link
Contributor

xPaw commented Feb 17, 2022

I upgraded from PHP 7.4 to 8.1 and noticed this issue where floats are being stored as negative now. I didn't upgrade memcached server. Unsure if it worked on PHP 8.0.

Previous version: php7.4-memcached 3.1.5+2.2.0-14+0~20220117.37+debian10~1.gbpc8d81e
Version: php8.1-memcached 3.1.5+2.2.0-14+0~20220117.37+debian11~1.gbpc8d81e
(deb.sury.org package)

$Memcached = new Memcached();
$Memcached->addServer( '/run/memcached/memcached.sock', 0 );
$Memcached->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_PHP);

var_dump($Memcached->set( 'testkey', 1337.123, 60 ));
var_dump($Memcached->get( 'testkey'));

var_dump($Memcached->set( 'testkey2', -400.100, 60 ));
var_dump($Memcached->get( 'testkey2'));

var_dump($Memcached->set( 'testkey3', 600, 60 ));
var_dump($Memcached->get( 'testkey3'));

var_dump($Memcached->set( 'testkey4', ['test' => 500.60], 60 ));
var_dump($Memcached->get( 'testkey4'));

Output:

bool(true)
float(-1337.123)
bool(true)
float(-400.1)
bool(true)
int(600)
bool(true)
array(1) {
  ["test"]=>
  float(500.6)
}

Seems like this problem is only observed for bare float values, and not when they're in an array.

Verified that it is being stored like this:

$ memccat --servers=/run/memcached/memcached.sock testkey
-1337.123

$ memccat --servers=/run/memcached/memcached.sock testkey4
a:1:{s:4:"test";d:500.6;}

I initially assumed it was an igbinary issue but changing to SERIALIZER_PHP still observes this issue.

strace confirms this:

socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 4
connect(4, {sa_family=AF_UNIX, sun_path="/run/memcached/memcached.sock"}, 110) = 0
sendto(4, "set testkey 2 60 9\r\n-1337.123\r\n", 31, MSG_NOSIGNAL, NULL, 0) = 31
recvfrom(4, "STORED\r\n", 8196, MSG_NOSIGNAL, NULL, NULL) = 8
@remicollet
Copy link
Collaborator

Please try 3.2.0RC1

@SerafimArts
Copy link

SerafimArts commented Apr 14, 2022

Reproduced the same problem.

3.2.0 (release build) exactly fixes this issue.

P.S. I think the issue can be closed. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants