Created
March 24, 2017 14:43
-
-
Save h1kkan/713c25e49eaa44f0475d8165fd140c48 to your computer and use it in GitHub Desktop.
Easy way to test services with this file
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_server=""; | |
$redis_port=""; | |
$redis_connetion_timeout="5"; | |
$redis_test_key="redis_check"; | |
$redis_test_value=""; | |
$mysql_server=""; | |
$mysql_user=""; | |
$mysql_password=""; | |
$mysql_dbname=""; | |
$mysql_test_tablename="mysql_check"; //will be created as test table and then dropped | |
$mysql_test_record=""; //will be inserted to test table | |
$redis = new Redis(); | |
if (!$redis->connect($redis_server, $redis_port, $redis_connetion_timeout)) { | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("REDIS OPEN CONNECTION: ERROR "."<br>"."\n"); | |
} else { | |
echo "REDIS OPEN CONNECTION: OK"."<br>"."\n"; | |
} | |
if (!$redis->ping()) { | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("REDIS PING: ERROR"."<br>"."\n"); | |
} else { | |
echo "REDIS PING: OK"."<br>"."\n"; | |
} | |
if (!$redis->set($redis_test_key, $redis_test_value)) { | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("REDIS SET KEY: ERROR"."<br>"."\n"); | |
} else { | |
echo "REDIS SET KEY: OK"."<br>"."\n"; | |
} | |
if (!$redis->exists($redis_test_key)) { | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("REDIS CHECK KEY EXISTS: ERROR"."<br>"."\n"); | |
} else { | |
echo "REDIS CHECK KEY EXISTS: OK"."<br>"."\n"; | |
} | |
if (!($redis_check = $redis->get($redis_test_key))) { | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("REDIS GET KEY: ERROR"."<br>"."\n"); | |
} else { | |
if (!($redis_test_value == $redis_check)) { | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("REDIS COMPARE KEY: ERROR"."<br>"."\n"); | |
} | |
echo "REDIS GET AND COMPARE KEY: OK"."<br>"."\n"; | |
} | |
if (!$redis->delete($redis_test_key)) { | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("REDIS DELETE KEY: ERROR"."<br>"."\n"); | |
} else { | |
echo "REDIS DELETE KEY: OK"."<br>"."\n"; | |
} | |
if (!$redis->close()) { | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("REDIS CLOSE CONNECTION: ERROR"."<br>"."\n"); | |
} else { | |
echo "REDIS CLOSE CONNECTION: OK"."<br><br><br>"."\n"; | |
} | |
if (!$mysql_link=mysqli_connect($mysql_server,$mysql_user,$mysql_password,$mysql_dbname)) { | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("MYSQL OPEN CONNECTION: ERROR ".mysqli_connect_error()."<br>"."\n"); | |
} else { | |
echo "MYSQL OPEN CONNECTION: OK"."<br>"."\n"; | |
} | |
if (!mysqli_select_db($mysql_link,$mysql_dbname)) { | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("MYSQL DB CONNECTION: ERROR ["."Could not open the db '$dbname'"."]<br>"."\n"); | |
} else { | |
echo "MYSQL DB CONNECTION: OK"."<br>"."\n"; | |
} | |
$sql="CREATE TABLE `".$mysql_test_tablename."` (`check_text` varchar(70) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; | |
if(!mysqli_query($mysql_link,$sql)){ | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("MYSQL TEST TABLE CREATION: ERROR [ ".mysqli_error($mysql_link)." ]<br>"."\n"); | |
} else { | |
echo "MYSQL TEST TABLE CREATION: OK"."<br>"."\n"; | |
} | |
$sql = "INSERT INTO `".$mysql_test_tablename."` (`check_text`) VALUES ('".$mysql_test_record."')"; | |
if(!mysqli_query($mysql_link,$sql)){ | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("MYSQL TEST RECORD INSERT: ERROR [ ". mysqli_error($mysql_link)." ]<br>"."\n"); | |
} else { | |
echo "MYSQL TEST RECORD INSERT: OK"."<br>"."\n"; | |
} | |
$sql = "SELECT * FROM `".$mysql_test_tablename."`"; | |
if(!$result = mysqli_query($mysql_link,$sql)){ | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("MYSQL TEST RECORD SELECT: ERROR [ ". mysqli_error($mysql_link)." ]<br>"."\n"); | |
} else { | |
$array = array(); | |
while($row = mysqli_fetch_array($result)){$array[]=$row;} | |
if($array[0][0] != $mysql_test_record){ | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("MYSQL COMPARE TEST RECORD: ERROR [ TEST RECORD NOT VALID ]<br>"."\n"); | |
} | |
mysqli_free_result($result); | |
echo "MYSQL TEST RECORD SELECT AND COMPARE: OK"."<br>"."\n"; | |
} | |
$sql = "DELETE FROM `".$mysql_test_tablename."` WHERE `check_text`='".$mysql_test_record."';"; | |
if(!mysqli_query($mysql_link,$sql)){ | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("MYSQL TEST RECORD DELETE: ERROR [ ". mysqli_error($mysql_link)." ]<br>"."\n"); | |
} else { | |
echo "MYSQL TEST RECORD DELETE: OK"."<br>"."\n"; | |
} | |
$sql="DROP TABLE `".$mysql_test_tablename."`;"; | |
if(!mysqli_query($mysql_link,$sql)){ | |
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Internal Server Error', true, 503); | |
die("MYSQL TEST TABLE DROP: ERROR [ ".mysqli_error($mysql_link)." ]<br>"."\n"); | |
} else { | |
echo "MYSQL TEST TABLE DROP: OK"."<br>"."\n"; | |
} | |
$mysqli_close($mysql_link); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment