-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
97 lines (77 loc) · 2.62 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/* credentials */
$db_user = 'infratest';
$db_pass = 'infra1234';
/* FIX THIS LATER */
/* $db_host = 'app'; */
$db_host = 'localhost';
$db_database = "infratest";
$memcache_host = 'front';
/* MySQL */
try {
$db_link = mysql_connect($db_host, $db_user, $db_pass);
if (!$db_link) {
$db_result = "<p>Error: Could not connect to db host '" . $db_host . "</p>";
} else {
mysql_select_db($db_database, $db_link);
$result = mysql_query("INSERT INTO test VALUES(null, " . mysql_real_escape_string(rand(100000, 999999)) . ", NOW() )");
if (!$result) {
$db_result = "<p>Error: Could not insert into database" . htmlentities(mysql_error($db_link)) . "</p>" . $db_link;
} else {
$result = mysql_query("SELECT * from test ORDER BY id DESC LIMIT 0, 25");
if (!$result) {
$db_result = "<p>Error: Could not read from database" . htmlentities(mysql_error($db_link)) . "</p>";
} else {
$cached_val = null;
$db_result = "<p>DB Read and Write successful</p>\n";
$db_result .= "<h3>Recent Rows:</h3>\n <ul>\n";
while ($row = mysql_fetch_assoc($result)) {
$line = "<li>ID: " . htmlentities($row["id"]) . " Value: " . htmlentities($row["value"]) . " Created at: " . htmlentities($row["created_at"]) . "</li>\n";
$db_result .= $line;
if (!$cached_val) {
$cached_val = $line;
}
}
$db_result .= "</ul>\n";
}
}
mysql_close();
}
} catch (Exception $e) {
$db_result = "<p>Error with DB Test: " . htmlentities($e->getMessage()) . "</p>";
}
/* Memcache Tests */
try {
$memcache = new Memcache;
$memcache->addServer($memcache_host, 11211);
if ( $memcache->set('infratest_memcache', $cached_val) ) {
$memcache_result = "<p>Set memcache value successfully</p>";
$memcache_result .= "GET value: " . $memcache->get('infratest_memcache');
}
else {
$memcache_result = "<p>Error: Did not set memcache value</p>";
}
} catch (Exception $e) {
$memcache_result = "<p>Error with Memcache Test: " . htmlentities($e->getMessage()) . "</p>";
}
/* Environment */
$env_result = "<ul>";
foreach ($_SERVER as $key => $value) {
$env_result .= "<li>" . htmlentities($key) . " => " . htmlentities($value) . "</li>";
}
$env_result .= "</ul>";
?>
<html>
<head>
<title>Infrastructure Engineer Test</title>
</head>
<body>
<h1>Infrastructure Engineer Test</h1>
<h2>Environment</h2>
<!--<?php echo $env_result; ?>-->
<h2>Mysql Test</h2>
<p><?php echo $db_result ?></p>
<h2>Memcache Test</h2>
<p><?php echo $memcache_result ?></p>
</body>
</html>