-
-
Save pulecp/916bf5ad56d341c63ab7 to your computer and use it in GitHub Desktop.
Test redis status
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 | |
/* 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)); | |
?> |
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 | |
/* 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) { | |
http_response_code(500); | |
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") { | |
http_response_code(500); | |
die("Unable to write to Redis - got '$ln'\n"); | |
} else { | |
print("Redis write successfull...\n"); | |
} | |
fclose($fp); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment