Browse Source

Add update test for php-raw

Patrick Falls 12 years ago
parent
commit
46a00c881d
3 changed files with 49 additions and 0 deletions
  1. 1 0
      php/benchmark_config
  2. 47 0
      php/rawupdate.php
  3. 1 0
      php/setup.py

+ 1 - 0
php/benchmark_config

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

+ 47 - 0
php/rawupdate.php

@@ -0,0 +1,47 @@
+<?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
+));
+
+// Read number of queries to run from URL parameter
+$query_count = 1;
+if (TRUE === isset($_GET['queries'])) {
+  $query_count = $_GET['queries'];
+}
+
+// Create an array with the response string.
+$arr = array();
+$id = mt_rand(1, 10000);
+$randomNumber = mt_rand(1, 1000);
+
+// Define query
+$statement = $pdo->prepare('SELECT randomNumber FROM World WHERE id = :id');
+$statement->bindParam(':id', $id, PDO::PARAM_INT);
+
+$updateStatement = $pdo->prepare('UPDATE World SET randomNumber = :randomNumber WHERE id = :id');
+$updateStatement->bindParam(':id', $id, PDO::PARAM_INT);
+
+// For each query, store the result set values in the response array
+while (0 < $query_count--) {
+  $statement->execute();
+  
+  // Store result in array.
+  $world = array('id' => $id, 'randomNumber' => $statement->fetchColumn());
+  $world['randomNumber'] = $randomNumber
+  $updateStatement->execute();
+  
+  $arr[] = $world;
+  $id = mt_rand(1, 10000);
+  $randomNumber = mt_rand(1, 10000);
+}
+
+// Use the PHP standard JSON encoder.
+// http://www.php.net/manual/en/function.json-encode.php
+echo json_encode($arr);
+?>

+ 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/updateraw.php", "host=.*;", "host=" + args.database_host + ";")
   setup_util.replace_text("php/fortune.php", "host=.*;dbname", "host=" + args.database_host + ";dbname")
   setup_util.replace_text("php/deploy/php", "\".*\/FrameworkBenchmarks", "\"" + home + "/FrameworkBenchmarks")
   setup_util.replace_text("php/deploy/php", "Directory .*\/FrameworkBenchmarks", "Directory " + home + "/FrameworkBenchmarks")