Valkey: Handle PHP sessions with Valkey

This documentation is part of the Getting Started guide. You can view the complete guide here: Quick guide to getting started with Valkey.

👋 Welcome to the Stackhero documentation!

Stackhero provides a ready-to-use Valkey cloud solution offering numerous advantages, including:

  • Redis Commander web interface included.
  • Unlimited message size and transfers.
  • One-click simplified updates.
  • Optimal performance and enhanced security thanks to a private, dedicated infrastructure.

Save time and make your life easier: it only takes 5 minutes to try Stackhero's Valkey cloud hosting solution!

You can use the following code to store PHP sessions on Stackhero for Valkey:

<?php

// Parse Valkey URL
$valkey_url = parse_url('rediss://default:<yourPassword>@<XXXXXX>.stackhero-network.com:<PORT_TLS>');

// Configure session handler
ini_set('session.save_handler', 'redis');
ini_set('session.save_path', "tls://{$valkey_url['host']}:{$valkey_url['port']}?auth={$valkey_url['pass']}&timeout=5");

// Start the session
session_start();

?>