Getting Started with Valkey Glide PHP: A High‑Performance Redis‑Compatible Client
This guide introduces Valkey Glide PHP, the official high‑performance PHP client for the Valkey in‑memory datastore, explains its core Rust‑based architecture, shows three installation methods, highlights key features such as cluster‑aware commands and TLS, and provides ready‑to‑run code examples for single‑node and clustered environments.
What Is Valkey Glide PHP?
Valkey Glide PHP is the official PHP binding of the GLIDE project, an open‑source, high‑performance client library for Valkey (a Redis‑compatible in‑memory key‑value database). The core is written in Rust for memory safety and speed, and it is exposed to developers via a PHP extension.
What Is Valkey?
Valkey is an open‑source, high‑performance in‑memory key‑value datastore forked from Redis 7.2.4 and hosted by the Linux Foundation. It supports caching, session storage, message queues, Pub/Sub, real‑time leaderboards, and can even serve as a lightweight primary database. It offers rich data structures, microsecond‑level latency, clustering, persistence (RDB + AOF), and multithreaded optimizations.
Installation Options
Version 1.0.0 (stable) requires PHP ≥ 8.2/8.3 on Linux or macOS. Choose one of the following methods:
Method 1: Install via pie (recommended, from Packagist) pie install valkey-io/valkey-glide-php:1.0.0 Method 2: Install the release package via PECL
pecl install https://github.com/valkey-io/valkey-glide-php/releases/download/v1.0.0/valkey_glide-1.0.0.tgzMethod 3: Build from source (for custom development)
git clone --recurse-submodules https://github.com/valkey-io/valkey-glide-php.git
cd valkey-glide-php
python3 utils/patch_proto_and_rust.py
cargo build --release
phpize
./configure --enable-valkey-glide
make && make installAfter building, enable the extension in php.ini : extension=valkey_glide Verify the installation with: php -m | grep valkey_glide Note: Alpine Linux / musl libc is not currently supported.
Main Features of Valkey Glide PHP v1.0.0
Cluster‑Smart Operations : Automatically handles multi‑key commands (MGET, MSET, DEL, FLUSHALL) without manual slot grouping.
Unified Cluster Scan : Safe, convenient key iteration across shards.
phpredis Compatibility : Alias files allow existing new Redis() or new RedisCluster() code to work with minimal changes.
TLS Secure Connections : Full encrypted transport support (added in v1.0.0).
Pub/Sub, Scripts, Functions : Support for publish/subscribe, Lua scripting, and server‑side functions.
High‑Availability Design : Automatic topology discovery, reconnection, and read‑from‑replica strategies.
Rust Core : Memory‑safe, high‑performance implementation superior to pure PHP clients.
Additional Capabilities : OpenTelemetry observability, transaction support, IAM authentication (AWS ElastiCache), logging, etc.
Quick Start Examples
Native ValkeyGlide API (single node)
<?php
$client = new ValkeyGlide();
$client->connect(addresses: [['host' => '127.0.0.1', 'port' => 6379]]);
$client->set('welcome', 'Hello Valkey Glide PHP v1.0!');
echo $client->get('welcome') . PHP_EOL; // outputs: Hello Valkey Glide PHP v1.0!
$client->close();
?>phpredis Compatibility Mode (recommended for migration)
<?php
require_once 'vendor/valkey-io/valkey-glide-php/phpredis_aliases.php';
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('key', 'value from glide');
echo $redis->get('key') . PHP_EOL;
$redis->close();
?>Cluster Example (simplified)
<?php
$addresses = [
['host' => 'localhost', 'port' => 7001],
['host' => 'localhost', 'port' => 7002],
];
$client = new ValkeyGlideCluster(addresses: $addresses);
$client->set('foo', 'bar');
echo $client->get('foo');
?>Conclusion
Valkey Glide PHP v1.0.0 enables PHP developers to use familiar syntax while benefiting from the reliability, performance, and future‑proof features of the official Valkey client, making it an excellent choice for new projects or migrations from phpredis.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
