Comments (7)
This is the result of an overflow. The value of 4294967296 (2^32) is just overflowing to 0. Incrementing by 4294967297 will result in an increment by 1.
PHP-memcached is casting the offset value of the increment and decrement function to an unsigned int. This can be seen in the php_memcached.c file with the code below:
if (incr) {
status = memcached_increment(m_obj->memc, key, key_len, (unsigned int)offset, &value);
} else {
Fixing this is NOT as simple as just removing the cast from php_memcached.c. The memcached_increment function in libmemcached has a parameter called offset which is a uint32_t. This can be seen in the libmemcached file libmemcached/auto.cc with the code below:
memcached_return_t memcached_increment(memcached_st *memc,
const char *key, size_t key_length,
uint32_t offset,
uint64_t *value)
{
return memcached_increment_by_key(memc, key, key_length, key, key_length, offset, value);
}
You should probably file this issue with libmemcached. The function memcached_increment_by_key uses a uint64_t for the offset. It could be used by PHP-memcached instead but the API docs for libmemcached still list the offset parameter in memcached_increment_by_key as uint32_t. That can be seen here:
http://docs.libmemcached.org/memcached_auto.html
from php-memcached.
Confirmed this is still a bug in 3.0.0 with PHP 7.0 and PHP 7.1.
from php-memcached.
Ah, the value can be 64-bit, but the increment is limited to 32-bits per API call. The protocol does allow 64-bit increments, so it might only be an API issue in libmemcached: https://github.com/memcached/memcached/blob/master/doc/protocol.txt#L274
from php-memcached.
The problem still exists in the libmemcached:
http://bazaar.launchpad.net/~tangent-trunk/libmemcached/1.2/view/head:/libmemcached/auto.cc#L149
It is possible to work around this problem by replacing memcached_increment
with memcached_increment_by_key
in the code below.
https://github.com/php-memcached-dev/php-memcached/blob/master/php_memcached.c#L2224
That would look something like this:
if (by_key) {
if (incr) {
status = memcached_increment_by_key(intern->memc, ZSTR_VAL(server_key), ZSTR_LEN(server_key), ZSTR_VAL(key), ZSTR_LEN(key), offset, &value);
} else {
status = memcached_decrement_by_key(intern->memc, ZSTR_VAL(server_key), ZSTR_LEN(server_key), ZSTR_VAL(key), ZSTR_LEN(key), offset, &value);
}
} else {
if (incr) {
status = memcached_increment_by_key(intern->memc, ZSTR_VAL(key), ZSTR_LEN(key), ZSTR_VAL(key), ZSTR_LEN(key), offset, &value);
} else {
status = memcached_decrement_by_key(intern->memc, ZSTR_VAL(key), ZSTR_LEN(key), ZSTR_VAL(key), ZSTR_LEN(key), offset, &value);
}
}
from php-memcached.
The documentation is mis-matched to the actual code! Yes, memcached_increment_by_key accepts a 64-bit offset. This should be straightforward to fix in the master branch.
from php-memcached.
I can put together a PR if you want or you can take care of it if you want.
from php-memcached.
Thanks for the offer! I've got it going in #306
from php-memcached.
Related Issues (20)
- Incorrect PHP reflection type for Memcached::cas $cas_token HOT 1
- Release 3.2.1 HOT 8
- Support for PHP 8.1.7 HOT 5
- get returns random values when lower than default OPT_POLL_TIMEOUT is set HOT 42
- When using sasl return false
- What is $udf_flags in memcached-api.php?
- Use memcache on wordpress with php 8.1 HOT 2
- Installing in docker, with apache + php-7.4 | GC_REFCOUNT HOT 3
- Problem stored float value in PHP 8.1/8.2 HOT 1
- pickle.phar installation of memcached doesn't work anymore as of PHP 8.1.20 and PHP 8.2.7 HOT 3
- OPT_NOREPLY: touch() stuck forever
- Suspicion of php-memcached bug regarding persistent sessions resulting in rare cases of session mixup
- No updated DLL version available HOT 3
- please help install php 8.0 memcache in docker HOT 1
- Undocumented 3.2.0 change: non-ascii keys no longer supported. HOT 10
- PHP 8.3 HOT 1
- Release zstd support
- memcached.so: php_msgpack_serialize: symbol not found HOT 2
- memcached returns wrong values.
- get/getMulti return RES_NOTFOUND after buffered increment with result RES_UNKNOWN_READ_FAILURE with OPT_BINARY_PROTOCOL HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-memcached.