Commit Graph

508 Commits

Author SHA1 Message Date
Remi Collet
bb83855d18 use zend_ce_exception (#573) 2025-07-15 10:56:33 -07:00
Michael Wallner
4b5decdcb8 Merge branch 'master' into check_key_fix 2024-09-26 13:13:28 +02:00
Rasmus Lerdorf
d15c2e2fdf Check for spaces in keys when using the non-binary protocol even if key verification is disabled to avoid injection issues 2024-09-26 13:11:38 +02:00
Rasmus Lerdorf
da71ae0362 Fix more tests with a slight refactor 2024-09-26 13:11:38 +02:00
Rasmus Lerdorf
0987380a55 If client-side verify_key is not enabled, don't check it automatically 2024-09-26 13:11:38 +02:00
Remi Collet
899f0d5242 Fix incompatible pointer types 2024-09-26 12:24:59 +02:00
Rasmus Lerdorf
7f31d8651b The key length check was not taking the prefix into account 2024-03-07 10:36:43 -05:00
Rasmus Lerdorf
7fefcb7924 Make the compression_level at settable option and expand it to zlib (#540)
Make it possible to use setOption to set Memcached::OPT_COMPRESSION_LEVEL which
was missed in the original zstd PR #539

zlib compression was using the default zlib compression level of 6. With this PR
it is now possible to choose other levels for zlib as well. The default remains
at 6 so nothing will change for people upgrading unless they explicitly set a
different level.

Here is some more benchmarking data using php serialized data
https://gist.github.com/rlerdorf/b9bae385446d5a30b65e6e241e34d0a8

fastlz is not really useful at any value size anymore. Anybody looking for
lightning quick compression and decompression should use zstd at level 1.

compression_level is not applied to fastlz because it only has 2 levels and
php-memcached already switches from level 1 to 2 automatically for values larger
than 65535 bytes. Forcing it to one or the other doesn't seem useful.
2023-05-03 16:10:38 -07:00
Robert
e39a2e62f4 Add option to locally enforce payload size limit (#515)
Add a configuration option to enforce an item size limit on the client side. This avoids sending large items
over the wire and getting rejected by the server which can cause delays. The default is 0 for no limit.
The same error code RES_E2BIG is used for the client side limit as for the server side limit.
2023-04-27 08:48:49 -07:00
Rasmus Lerdorf
5833590296 zstd support (#539)
This adds zstd compression support.

The current two options, zlib and fastlz is basically a choice between performance and compression ratio.
You would choose zlib if you are memory-bound and fastlz if you are cpu-bound. With zstd, you get the
performance of fastlz with the compression of zlib. And often it wins on both. See this benchmark I ran
on json files of varying sizes: https://gist.github.com/rlerdorf/788f3d0144f9c5514d8fee9477cbe787

Taking just a 40k json blob, we see that zstd at compression level 3 reduces it to 8862 bytes. Our current
zlib 1 gets worse compression at 10091 bytes and takes longer both to compress and decompress.

      C Size  ratio%     C MB/s     D MB/s   SCORE      Name            File
        8037    19.9       0.58    2130.89       0.08   zstd 22         file-39.54k-json
        8204    20.3      31.85    2381.59       0.01   zstd 10         file-39.54k-json
        8371    20.7      47.52     547.12       0.01   zlib 9          file-39.54k-json
        8477    20.9      74.84     539.83       0.01   zlib 6          file-39.54k-json
        8862    21.9     449.86    2130.89       0.01   zstd 3          file-39.54k-json
        9171    22.7     554.62    2381.59       0.01   zstd 1          file-39.54k-json
       10091    24.9     153.94     481.99       0.01   zlib 1          file-39.54k-json
       10646    26.3      43.39    8097.40       0.01   lz4 16          file-39.54k-json
       10658    26.3      72.30    8097.40       0.01   lz4 10          file-39.54k-json
       13004    32.1    1396.10    6747.83       0.01   lz4 1           file-39.54k-json
       13321    32.9     440.08    1306.03       0.01   fastlz 2        file-39.54k-json
       14807    36.6     444.91    1156.77       0.01   fastlz 1        file-39.54k-json
       15517    38.3    1190.79    4048.70       0.02   zstd -10        file-39.54k-json

The fact that decompression a dramatically faster with zstd is a win for most common memcache uses
since they tend to be read-heavy. The PR also adds a `memcache.compression_level` INI switch which
currently only applies to zstd compression. It could probably be made to also apply to zlib and fastlz.
2023-04-27 08:32:10 -07:00
Remi Collet
811c8a1422 Fix #522 Signed integer overflow (#526) 2023-02-02 11:42:07 -08:00
Remi Collet
ce2dfa5e64 mark password as a sensitive param for 8.2 (#516)
* mark password as a sensitive param for 8.2
2022-07-28 09:28:33 +02:00
Remi Collet
d8f6f1c899 Merge pull request #488 from remicollet/issue-awesome
Improve phpinfo information
2022-03-07 14:33:04 +01:00
Aaron Stone
9cd4a01d99 Merge pull request #474 from m6w6/fix-memcachedserver
fix MemcachedServer
2021-08-22 22:05:26 -07:00
hulk
e6df8ab3f6 FIX: store_retry_count shouldn't be set implicitly (#452)
It's wired that store commands would be auto-retry implicitly while the default value of store_retry_count was 2, as well as the timeout, would be 3 times in those store commands which may confuse users. IMHO, the retry should be set explicitly instead of implicitly.
2021-08-22 21:57:11 -07:00
Timo Tijhof
6d457155fb Remove "failed to set key" warning from setMulti (#490)
This was introduced in https://github.com/php-memcached-dev/php-memcached/commit/6837d89494,
pull https://github.com/php-memcached-dev/php-memcached/pull/214. I suspect it
may have been a left-over from debugging something. The test was later
changed in 6837d89494 to expect the warning in question, although other
similar tests don't encounter such warning currently.

It appears no other Memcached methods emit a PHP Warning when they encounter
a write read or failure. Instead, they typically turn their return value
into boolean false, and provide details via getResultMessage().

The introduction of this warning since php-memcached 3.0 has led to a number
of confused consumers (locally #260, #409, #450, and more reports
within downstream issue trackers).

Closes https://github.com/php-memcached-dev/php-memcached/issues/409.
2021-08-22 21:56:19 -07:00
Remi Collet
13ba74317d Improve phpinfo information
- display libmemcached-awesome when used (since 1.1.1)
- display both builtime and runtime versions when different
2021-07-27 08:35:08 +02:00
Michael Wallner
9840866332 valgrind 2021-07-23 14:55:28 +02:00
Michael Wallner
8ed8092c7f fix MemcachedServer
related: #418, m6w6/libmemcached#94
2021-07-23 14:55:27 +02:00
Rasmus Lerdorf
7bbf4fbad3 Expose internal key check via checkKey() method Make ascii key check consistent with libmemcached's isgraph() check Add test to check that they match 2021-06-09 18:06:46 +02:00
Joe Watkins
51c9baf49f fix zpp in mem_cas_impl 2021-06-09 14:58:37 +02:00
Joe Watkins
015776be90 fix incorrect zp, fixes #484 2021-06-09 14:53:43 +02:00
Remi Collet
9a429d43f8 Promote error "Memcached constructor was not called" to exception with PHP 8 (#465)
For consistency with other PHP 8 extensions.
2020-11-17 03:04:15 -08:00
SpencerMalone
f97b2e3ad9 Include a fuller list of response constants from libmemcached (#457) 2020-10-09 04:49:58 -07:00
Aaron Stone
7120d80cb9 Set TCP_NODELAY when setting binary protocol (#421)
* Set TCP_NODELAY when setting binary protocol
* Add braces to the check_set_behavior macro
2020-10-09 03:23:41 -07:00
hulk
a452d9a1e5 MOD: don't re-set the libmemcached option if not modified (#451)
libmemcached would close all connections if the option(like MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)
was set, even though value wasn't modified.
2020-10-09 02:53:09 -07:00
Remi Collet
baa6bfda6f cleanup HAVE_SPL, removed in 8 as always there 2020-10-08 13:48:30 +02:00
Remi Collet
e8f53777d3 generate arginfo from stub for PHP 7 and 8 2020-10-08 12:21:57 +02:00
Po-Chuan Hsieh
03f034f63e Fix build with PHP 7.4 (#445)
Build error on FreeBSD with PHP 7.4 RC6:
--- php_memcached.lo ---
/wrkdirs/usr/ports/databases/pecl-memcached/work-php74/memcached-3.1.4/php_memcached.c:3237:7: error: expected ';' after expression
        ulong key_index;
             ^
             ;
/wrkdirs/usr/ports/databases/pecl-memcached/work-php74/memcached-3.1.4/php_memcached.c:3237:2: error: use of undeclared identifier 'ulong'
        ulong key_index;
        ^
/wrkdirs/usr/ports/databases/pecl-memcached/work-php74/memcached-3.1.4/php_memcached.c:3237:8: error: use of undeclared identifier 'key_index'
        ulong key_index;
              ^
/wrkdirs/usr/ports/databases/pecl-memcached/work-php74/memcached-3.1.4/php_memcached.c:3250:49: error: use of undeclared identifier 'key_index'
        ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(options), key_index, key, value) {
                                                       ^
/wrkdirs/usr/ports/databases/pecl-memcached/work-php74/memcached-3.1.4/php_memcached.c:3255:44: error: use of undeclared identifier 'key_index'
                        if (!php_memc_set_option(intern, (long) key_index, value)) {
                                                                ^
5 errors generated.
*** [php_memcached.lo] Error code 1
2019-11-18 10:01:10 -08:00
Tyson Andre
37f2cf98ae Fix segfault for unknown memcache flags
Set retval to false so that the resulting uninitialized zval won't be
used.
2019-03-11 17:40:40 -04:00
Aaron Stone
c85d9029fb Fix --disable-memcached-session by ifdef-ing session INI handler callbacks (#420)
Resolves #396
2018-12-24 13:16:42 -08:00
Remi Collet
35292435e2 fix build warning (#417) 2018-12-22 08:00:04 -08:00
Aaron Stone
9f7d049737 Fix zend_string warning 2018-12-21 04:46:06 -08:00
Aaron Stone
2aa0d68a77 Nits 2018-12-21 01:28:08 -08:00
Xander
6d8f5d524f Windows fixes (#411) 2018-11-14 16:27:53 -08:00
Tom Van Looy
549e7c8a3a Change session_lock default ini values (#350) 2018-07-20 16:01:55 -07:00
Peter Kokot
f5f84c592f Remove unused Git attributes ident (#402)
The $Id$ keywords were used in Subversion where they can be substituted
with filename, last revision number change, last changed date, and last
user who changed it.

In Git this functionality is different and can be done with Git attribute
ident. These need to be defined manually for each file in the
.gitattributes file and are afterwards replaced with 40-character
hexadecimal blob object name which is based only on the particular file
contents.

This patch simplifies handling of $Id$ keywords by removing them since
they are not used anymore.
2018-06-30 10:00:44 -07:00
Aaron Stone
f4dafd207e Add INI setting to choose session consistent hash (ketama or ketama_weighted) (#392)
Provides a new INI option to select the same consistent hash behavior as
older versions of php-memcached, to aid in migration from PHP 5.x to PHP
7.x. When `memcached_sess_consistent_hash_type` is set to `ketama` or
`ketama_weighted`, that sets either MEMCACHED_BEHAVIOR_KETAMA or
MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, respectively.

Resolves #344
2018-04-08 19:41:01 -07:00
Aaron Stone
8bfdbcc906 Update for new PHP 7.3 REFCOUNT macros (#390) 2018-03-29 23:26:46 -07:00
Aaron Stone
e0ccf87c51 Avoid hanging getStats() when binary protocol and non-blocking are both enabled
Fixes #348.
2018-01-23 06:27:26 -08:00
Aaron Stone
2c693c7a9b Allow connect_timeout value of -1 and show Unlimited in phpinfo() 2018-01-23 03:52:34 -08:00
Aaron Stone
f54ed299c0 Use STD_PHP_INI_BOOLEAN to correctly display php.ini booleans 2018-01-23 03:32:07 -08:00
Aaron Stone
deb451ae9e Fix wrong undefs of local macros for registering constants 2018-01-21 21:47:48 -08:00
Aaron Stone
2fc7d3659c Fix wrong INI parsing method for memcached.sess_randomize_replica_read 2018-01-21 21:46:56 -08:00
Aaron Stone
5c6de2b0e4 Add support for libmemcached encryption (#381)
This feature is fully supported in libmemcached 1.0.18 and higher,
but has a notable bug in the original implementation in libmemcached
versions 1.0.6 - 1.0.17 that the encryption key, once set, cannot be
changed otherwise all further get/set operations fail.
2018-01-20 08:04:40 -08:00
Aaron Stone
7ed5b38a3e Removed ifdef 0 code and trivial block cleanup 2018-01-18 19:21:41 -08:00
Aaron Stone
5edd5bac25 Restore default value memcached.sess_prefix = "memc.sess.key."
Resolves #340
2017-11-20 23:49:58 -06:00
Aaron Stone
f82e6845af Use new fast_zpp parameter parsing API (#311)
The one that took a while to figure out was zpp("f!") to Z_PARAM_FUNC_EX(fci, fcc, 1, 0)
2017-11-20 23:15:34 -06:00
Aaron Stone
be93a459ee Fix the key validity tests to handle strings with embedded nulls 2017-07-11 14:04:01 -07:00
Aaron Stone
bf16783ef9 Merge pull request #330 from remicollet/issue-ini
Refresh memcached.ini and set sess_binary_protocol off by default with older libmemcached
2017-06-13 10:42:33 -05:00