Skip to content

Instantly share code, notes, and snippets.

@VerosK
Created September 24, 2015 15:28
Show Gist options
  • Save VerosK/d8999bc64f3c923aa015 to your computer and use it in GitHub Desktop.
Save VerosK/d8999bc64f3c923aa015 to your computer and use it in GitHub Desktop.
Test redis status
<?php
/* Redis PHP stats dump
* Based on code https://gist.github.com/putzflorian/45c137a8d7868d4b6250
*/
define(REDIS_TIMEOUT, 2);
$fp = fsockopen('127.0.0.1', 6379, $errno, $errstr, REDIS_TIMEOUT);
if (!$fp) {
die($errstr);
}
$data = array();
fwrite($fp, "INFO\r\nQUIT\r\n");
while (!feof($fp)) {
$ln = fgets($fp);
$parts = explode(':', trim($ln), 2);
if (isset($parts[1])) {
$data[$parts[0]] = $parts[1];
}
}
fclose($fp);
print(json_encode($data));
?>
<?php
/* Redis PHP write test
* Inspired by code https://gist.github.com/putzflorian/45c137a8d7868d4b6250
*/
define(REDIS_TIMEOUT, 2);
define(REDIS_ADDRESS, '127.0.0.1');
$fp = fsockopen(REDIS_ADDRESS, 6379, $errno, $errstr, REDIS_TIMEOUT);
if (!$fp) {
die($errstr);
}
/* Write string to Redis with short TTL
*/
fwrite($fp, "SET is-redis-alive yes EX 10\r\n");
$ln = trim(fgets($fp));
if ($ln != "+OK") {
die("Unable to write to Redis - got '$ln'\n");
} else {
print("Redis write successfull...\n");
}
fclose($fp);
?>
@pulecp
Copy link

pulecp commented Oct 8, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment