Skip to content

Instantly share code, notes, and snippets.

@arashatt
Last active June 6, 2024 20:38
Show Gist options
  • Select an option

  • Save arashatt/1c9683fe5b93a946fef11c169ec52f7d to your computer and use it in GitHub Desktop.

Select an option

Save arashatt/1c9683fe5b93a946fef11c169ec52f7d to your computer and use it in GitHub Desktop.
<?php
if (class_exists('Memcache')) {
// Create a new Memcache instance
$memcache = new Memcache();
// Add a Memcache server
$memcache->connect('127.0.0.1', 11211);
// Test storing a value
$key = 'test_key';
$value = 'Hello, Memcache!';
$expiration = 3600; // 1 hour
$memcache->set($key, $value, false, $expiration);
echo "Stored value in Memcache: $value\n";
// Test retrieving the value
$retrieved_value = $memcache->get($key);
echo "Retrieved value from Memcache: $retrieved_value\n";
// Test deleting the value
$memcache->delete($key);
$deleted_value = $memcache->get($key);
if ($deleted_value === false) {
echo "Value successfully deleted from Memcache.\n";
} else {
echo "Failed to delete value from Memcache.\n";
}
} else {
echo "Memcache class does not exist. Please ensure the Memcache extension is installed and enabled.";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment