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 offers a ready-to-use Valkey cloud solution that provides a host of benefits, including:

  • Redis Commander web UI included.
  • Unlimited message size and transfers.
  • Effortless updates with just a click.
  • Optimal performance and robust security powered by a private and dedicated VM.

Save time and simplify your life: 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();

?>