github valkey-io/valkey-glide-php v1.2.0

10 days ago

Key Features

  • Alpine Linux (musl) Support: The extension now builds and runs on Alpine Linux 3.19+ (x86_64 and aarch64).
  • PHP 8.4 and 8.5: Added PHP 8.4 and 8.5 to the supported versions and the CI test matrix.
  • Persistent Clients: Added persistent clients for PHP-FPM and other long-lived workers. connect(persistent_id: ...), ValkeyGlide::pconnect() and new ValkeyGlideCluster(persistent: true) keep the client open after the request and reuse it in later requests with the same configuration, so the connection (and, for clusters, topology discovery) is not repeated on every request. The new ini setting valkey_glide.max_persistent_clients (default 32) caps the number of kept clients per process (per thread under ZTS).
  • PHPRedis Key Prefixing: Added OPT_PREFIX (through setOption()/getOption()) and _prefix() for standalone and cluster clients. The prefix is applied to every key argument, including multi-key commands, script and function keys, commands queued in multi()/pipeline(), pub/sub channels, and the key that routes a cluster command. OPT_SCAN is now a PHPRedis-style bitmask (SCAN_PREFIX/SCAN_NOPREFIX, SCAN_RETRY/SCAN_NORETRY).
  • Mutual TLS (mTLS): Added client certificate support for standalone and cluster clients through advanced_config['tls_config'], either as bytes (client_cert/client_key) or as file paths (client_cert_path/client_key_path) with automatic certificate reloading (cert_reload_interval_seconds).
  • Sharded Pub/Sub for Cluster Clients: Added ssubscribe(), sunsubscribe(), spublish(), pubsub('shardnumsub', [...]) and PUBSUB SHARDCHANNELS to ValkeyGlideCluster. These previously threw "not yet supported".
  • AZ Affinity All Nodes Read Strategy: Added READ_FROM_AZ_AFFINITY_ALL_NODES, which serves reads from any node, primary or replica, in the client's availability zone.
  • OPT_SLAVE_FAILOVER for Clusters: ValkeyGlideCluster::setOption()/getOption() support FAILOVER_NONE, FAILOVER_ERROR, FAILOVER_DISTRIBUTE and FAILOVER_DISTRIBUTE_SLAVES, mapped to the matching GLIDE read strategy.
  • Node Discovery Mode: Added NodeDiscoveryMode (STANDARD, STATIC, DISCOVER_ALL) for standalone clients.
  • Circuit Breaker Configuration: Added circuit breaker configuration support.
  • Client Identification: Added lib_name and client_info_tag to the client configuration.
  • New Valkey Commands: Added DELIFEQ (Valkey 9.0), HGETDEL (Valkey 9.1) and SISMEMBER XX through sIsMemberIfExists() (Valkey 9.2). Also added BGSAVE (including SCHEDULE and CANCEL), BGREWRITEAOF, SAVE, LASTSAVE, RESET, CLIENT PAUSE/UNPAUSE, CLIENT TRACKINGINFO, MIGRATE, FAILOVER, REPLICAOF, MONITOR, LOLWUT, CONFIG for cluster clients, LATENCY HISTORY/LATEST/RESET, and MEMORY DOCTOR/MALLOC-STATS/PURGE/STATS.
  • PHPRedis Compatibility Methods: Added getLastError() and clearLastError().
  • Memory-Safety and PHPRedis-Parity Fixes: Fixed heap corruption, double frees, use-after-free and out-of-bounds writes in many commands (zAdd(), sort(), fcall(), list pushes, hRandField(), hGetEx(), del()/unlink(), zRandMember(), dbSize(), pExpireTime() and others), plus crashes in pub/sub, address resolver, OpenTelemetry configuration and fork() handling. The PHPRedis-parity changes below are listed under Migration Changes, each with migration steps.

Migration Changes

These changes bring the client closer to PHPRedis behavior or close safety gaps. Each item lists what changed and how to adjust.

  • Cluster reads default to primaries. ValkeyGlideCluster constructed with PHPRedis-style parameters ($seeds, $auth, ...) now reads from primaries when read_from is not given, matching PHPRedis RedisCluster. It previously defaulted to READ_FROM_PREFER_REPLICA (#369).
    • Migration: to keep replica reads, pass read_from: ValkeyGlide::READ_FROM_PREFER_REPLICA, or set OPT_SLAVE_FAILOVER to FAILOVER_DISTRIBUTE_SLAVES.
  • AZ-affinity strategies require client_az. READ_FROM_AZ_AFFINITY, READ_FROM_AZ_AFFINITY_REPLICAS_AND_PRIMARY and READ_FROM_AZ_AFFINITY_ALL_NODES configured without a valid client_az now throw at client creation. Before, the core logged a warning and downgraded the strategy to PreferReplica. A client_az that is empty, whitespace-only, contains a NUL byte, or has leading or trailing whitespace is rejected (#316).
    • Migration: set client_az to the availability zone name, with no surrounding whitespace. If you do not want AZ-aware reads, choose another read strategy such as READ_FROM_PREFER_REPLICA.
  • IAM authentication requires TLS. Configuring IAM auth without TLS is rejected at client creation instead of sending the token over a plaintext connection (#391).
    • Migration: enable TLS in the client configuration of every client that uses IAM auth.
  • zRem() and zMscore() convert members like zAdd(). Non-string members are converted with PHP's string conversion, as PHPRedis does. zRem($key, false) now removes the member "" instead of "0", and zRem($key, 1.23456789) removes "1.23456789" instead of "1.23457" (#380).
    • Migration: to match a member stored in the old form, pass that string, for example zRem($key, '0').
  • Floats are no longer rounded to six significant digits. Values, members and fields are converted as PHP converts floats to strings, and numbers a command takes as a double are sent in the shortest form that reads back as the same double (#382).
    • Migration: if you relied on the rounding, round the value yourself before the call, for example with round() or sprintf('%.6g', $value). Members stored from a rounded float must be addressed with the stored string.
  • hGetEx() returns false for a missing field. It returned null, and now matches hMget(), hGetDel() and PHPRedis (#415).
    • Migration: replace === null and is_null() checks on hGetEx() results with === false.
  • hRandField() follows PHPRedis return shapes (#421, #443):
    • count => 1 returns an array, as every other count does. It returned a single field as a string.
    • count => 0 means no count: it returns a single field, or one field => value pair with WITHVALUES. It returned false.
    • Option keys are case-insensitive, and WITHVALUES can be passed as a plain value (['WITHVALUES']). Both were ignored before.
    • A missing hash with a count or WITHVALUES returns [] instead of false.
    • With withvalues, numeric field names are returned as integer array keys ('7' becomes 7).
    • Migration: read the first element of the array when you pass count => 1, test for an empty array instead of false on a missing hash, and compare field names with loose equality or cast them to strings where you used strict string comparison.
  • object() accepts only four subcommands. It sends REFCOUNT, IDLETIME, FREQ and ENCODING, matched exactly and case-insensitively. Any other subcommand, including HELP and prefixes such as REF, emits the warning "Invalid subcommand sent to OBJECT" and returns false without sending anything. Before, the key was sent as the command name, so object('HELP', 'FLUSHDB') flushed the database (#443).
    • Migration: use the full subcommand name. For OBJECT HELP or other subcommands, use rawcommand().
  • xAdd() with maxlen 0 no longer trims the stream. MAXLEN is sent only when it is positive. Before, MAXLEN 0 emptied the stream (#443).
    • Migration: to empty a stream, del() the key or trim it explicitly with xTrim().
  • OPT_REPLY_LITERAL is now 8, as in PHPRedis. It was 1, the PHPRedis value of OPT_SERIALIZER. Option 1 still accepts a bool for reply literals but is deprecated (#368).
    • Migration: use the ValkeyGlide::OPT_REPLY_LITERAL constant instead of a literal 1. PHPRedis code that sets a serializer no longer turns on reply literals by accident.
  • Batch behavior changed. rawcommand(), eval(), evalSha(), eval_ro(), evalsha_ro() and functionLoad() inside multi() or pipeline() are now queued with the batch and return the client, instead of running immediately outside it. exec() after an empty multi() or pipeline() returns [] and leaves batch mode instead of returning false (#347, #413).
    • Migration: read results of these commands from the array that exec() returns. Move a command out of the batch if you need its result immediately. Check exec() for an empty array instead of false. In a batch, rawcommand() refuses node routes and the commands SELECT, AUTH, HELLO, CLIENT SETNAME and RESET (it returns false).
  • Constructing and cloning clients. ValkeyGlideCluster::__construct() on an already connected object throws instead of replacing the client, and clone on a ValkeyGlide or ValkeyGlideCluster object throws an Error (#350).
    • Migration: create a new object instead of calling the constructor again or cloning.
  • Clients inherited through fork(). The child no longer closes an inherited client. Calling a method on it in the child throws ValkeyGlideException, except close(), getLastError(), clearLastError(), getOption() and setOption() (#351).
    • Migration: do not use a parent's client in a forked child. Run GLIDE commands in the parent, or create the client in the child. Creating a new client in a child after the parent has used GLIDE can still crash or hang until the core is fixed.
  • Pub/sub subscribers have a bounded queue. Each subscriber queues at most 10,000 messages or 64 MiB of payload. A single larger message is still delivered when the queue is empty. When a slow callback falls behind, newer messages are dropped and a warning with the drop count is logged, at most once per second. Before, every message was queued with no limit (#363, #365).
    • Migration: keep subscriber callbacks fast, for example by handing messages to a queue or worker. Watch the logs for the drop warning. The limits are fixed and not configurable.

New Requirements

  • Building from source now needs the protobuf-c library and compiler (libprotobuf-c-dev, protobuf-c-compiler), libffi development headers, python3 and cbindgen (cargo install cbindgen). See the README for per-distribution package lists.

What's Changed

The curated, user-facing list of every change in this release is in CHANGELOG.md. Pull requests are listed below by category. Dependabot and other bot updates are omitted.

Features (31)
Fixes (24)
  • fix(php): fix issues from the rc2 bug bash by @prateek-kumar-improving in #442
  • fix(logger): logger creation returns false instead of crashing when logfile unwritable by @leslie-bq in #445
  • fix(php): return false for missing fields from hGetEx() by @uintaam in #417
  • fix(php): send float arguments without rounding them to six digits by @uintaam in #418
  • fix(php): queue rawcommand() in multi() and pipeline() by @uintaam in #419
  • fix(php): free queued result state when a batch is not executed by @uintaam in #416
  • fix(php): handle hRandField() options and replies as PHPRedis does by @uintaam in #422
  • fix(php): size zset argument buffers and stop double frees in zAdd() by @uintaam in #411
  • fix(php): keep hGetEx() arguments alive until exec() in a batch by @uintaam in #412
  • fix(php): record rawcommand() errors for getLastError() by @uintaam in #410
  • fix(php): return false from dbSize() and pExpireTime() when the command fails by @uintaam in #409
  • fix(php): fix memory-safety bugs in SORT, FCALL, list push, HRANDFIELD by @prateek-kumar-improving in #425
  • fix(php): free an address resolver when its client is closed, not at request shutdown by @uintaam in #397
  • fix(php): use the PHPRedis value 8 for OPT_REPLY_LITERAL by @uintaam in #358
  • fix(php): stop sending a 0-second periodic check interval for cluster clients by @uintaam in #355
  • fix(php): apply an integer timeout passed to connect() by @uintaam in #356
  • fix(php): require TLS for IAM auth by @jeremyprime in #391
  • fix(php): send empty-string keys, values and members to the server by @uintaam in #393
  • fix(php): only run the PHP address resolver on the PHP thread by @uintaam in #357
  • fix(php): queue EVAL and FUNCTION LOAD in batches, fix empty EXEC and FUNCTION LOAD REPLACE by @uintaam in #347
  • fix(php): do not close or use clients inherited through fork() by @uintaam in #351
  • fix(php): make the pub/sub push callback thread-safe by @uintaam in #364
  • fix(php): release pub/sub registry per request, guard cluster re-construct, check NULL connection response, forbid clone, init varargs by @uintaam in #350
  • fix(compatibility): track getLastError/clearLastError as missing PHPRedis methods by @tnucera in #220
Tests, CI, docs and maintenance (21)
  • ci: stabilize PHP setup in build-php-wrapper on Ubuntu by @leslie-bq in #452
  • test(php): use a non-shared integer in the OBJECT refcount test by @leslie-bq in #449
  • test(php): skip cluster SORT GET patterns test on Valkey < 8.0 by @leslie-bq in #447
  • cleanup: Issue templates ask for PHP version only instead of other languages that don't apply by @leslie-bq in #434
  • ci: fix the nightly full matrix (startup failure, ARM64 runners, LOLWUT test) by @uintaam in #408
  • ci: install PHP from packages.sury.org and move pinned jobs to ubuntu-26.04 by @uintaam in #386
  • test: improve test stability and cluster test isolation by @Big-Shark in #340
  • test(php): give test clients a 2 s connection timeout by @uintaam in #396
  • test(php): wait for BGSAVE on replicas before CANCEL in cluster tests by @uintaam in #389
  • ci: pin ubuntu-latest jobs to ubuntu-24.04 by @nderraugh in #390
  • test(php): fix flaky testExists and testFailoverSucceeds by @uintaam in #376
  • docs(php): fix AGENTS.md build/test commands and stale template text by @jeremyprime in #370
  • test(php): Improve stability of PubSub tests, add 5-time default retry for apt-get, pin Pluggy and Scancode version by @leslie-bq in #372
  • test(php): verify Valkey 9.2 INFO fields, config values and client flags by @currantw in #354
  • ci(php): test against Valkey 9.2.0-rc1 by @currantw in #346
  • ci(php): add PHP 8.4 and 8.5 to the supported versions matrix by @Big-Shark in #339
  • ci(ort): fix attribution build (ORT 59.0.0) by @prateek-kumar-improving in #336
  • Update submodule glide core by @prateek-kumar-improving in #325
  • Update dependencies in readme.md by @prateek-kumar-improving in #290
  • PHP: Fix version in workflow files by @prateek-kumar-improving in #260
  • PHP: fix ort workflow to verify signatures by @prateek-kumar-improving in #255

New Contributors

Full Changelog: v1.1.2...v1.2.0

Don't miss a new valkey-glide-php release

NewReleases is sending notifications on new releases.