Created
January 13, 2014 23:59
-
-
Save axolx/8410415 to your computer and use it in GitHub Desktop.
Script to test that PHP can connect to Memcache (from http://stackoverflow.com/questions/1463670/how-to-check-if-memcache-or-memcached-is-installed-for-php)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (class_exists('Memcache')) { | |
$server = 'SETME'; # Memcached server hostname | |
$memcache = new Memcache; | |
$isMemcacheAvailable = @$memcache->connect($server); | |
if ($isMemcacheAvailable) { | |
$aData = $memcache->get('data'); | |
echo '<pre>'; | |
if ($aData) { | |
echo '<h2>Data from Cache:</h2>'; | |
print_r($aData); | |
} else { | |
$aData = array( | |
'me' => 'you', | |
'us' => 'them', | |
); | |
echo '<h2>Fresh Data:</h2>'; | |
print_r($aData); | |
$memcache->set('data', $aData, 0, 300); | |
} | |
$aData = $memcache->get('data'); | |
if ($aData) { | |
echo '<h3>Memcache seem to be working fine!</h3>'; | |
} else { | |
echo '<h3>Memcache DOES NOT seem to be working!</h3>'; | |
} | |
echo '</pre>'; | |
} | |
} | |
if (!$isMemcacheAvailable) { | |
echo 'Memcache not available'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment