Browse Source

beginning of php fortune test

Patrick Falls 12 years ago
parent
commit
45a4674d0c
4 changed files with 53 additions and 0 deletions
  1. 0 0
      php-slim/fortune.php
  2. 1 0
      php/benchmark_config
  3. 51 0
      php/fortune.php
  4. 1 0
      php/setup.py

+ 0 - 0
php-slim/fortune.php


+ 1 - 0
php/benchmark_config

@@ -13,6 +13,7 @@
       "setup_file": "setup",
       "db_url": "/dbraw.php",
       "query_url": "/dbraw.php?queries=",
+      "fortune_url": "/fortune.php"
       "port": 8080,
       "sort": 12
     }

+ 51 - 0
php/fortune.php

@@ -0,0 +1,51 @@
+<?php
+//
+// Database Test
+//
+
+// Database connection
+// http://www.php.net/manual/en/ref.pdo-mysql.php
+$pdo = new PDO('mysql:host=localhost;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', array(
+    PDO::ATTR_PERSISTENT => true
+));
+
+// Define query
+$statement = $pdo->prepare('SELECT * FROM Fortune');
+$statement->execute();
+  
+// Store result in array.
+$arr = $statment->fetchAll();
+$arr[] = array('id' => 0, 'message' => 'Additional fortune added at request time.');
+
+function cmp($a, $b) {
+  if ($a['message'] == $b['message']) {
+    return 0;
+  }
+  
+  return ($a['message'] < $b['message']) ? -1 : 1;
+}
+
+uasort($arr, 'cmp');
+?>
+<!DOCTYPE html>
+<html>
+<head>
+<title>Fortunes</title>
+</head>
+<body>
+<table>
+<tr>
+<th>id</th>
+<th>message</th>
+</tr>
+<?php
+foreach ($arr as &$value) {
+?>
+<tr>
+<td><?php echo return htmlspecialchars($value['id'], 'ENT_COMPAT | ENT_HTML401', 'UTF-8'); ?></td>  
+<td><?php echo return htmlspecialchars($value['message'], 'ENT_COMPAT | ENT_HTML401', 'UTF-8'); ?></td>
+</tr>
+<?php } ?>
+</table>
+</body>
+</html>

+ 1 - 0
php/setup.py

@@ -10,6 +10,7 @@ home = expanduser("~")
 def start(args):
   setup_util.replace_text("php/dborm.php", "@.*\/hello_world", "@" + args.database_host + "/hello_world")
   setup_util.replace_text("php/dbraw.php", "host=.*;", "host=" + args.database_host + ";")
+  setup_util.replace_text("php/fortune.php", "host=.*;", "host=" + args.database_host + ";")
   setup_util.replace_text("php/deploy/php", "\".*\/FrameworkBenchmarks", "\"" + home + "/FrameworkBenchmarks")
   setup_util.replace_text("php/deploy/php", "Directory .*\/FrameworkBenchmarks", "Directory " + home + "/FrameworkBenchmarks")
   setup_util.replace_text("php/deploy/nginx.conf", "root .*\/FrameworkBenchmarks", "root " + home + "/FrameworkBenchmarks")