|
@@ -1,47 +1,37 @@
|
|
<?php
|
|
<?php
|
|
// Set content type
|
|
// Set content type
|
|
-header("Content-type: application/json");
|
|
|
|
|
|
+header('Content-type: application/json');
|
|
|
|
|
|
// Database connection
|
|
// Database connection
|
|
// http://www.php.net/manual/en/ref.pdo-mysql.php
|
|
// http://www.php.net/manual/en/ref.pdo-mysql.php
|
|
// $pdo = new PDO('mysql:host=tfb-database;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass');
|
|
// $pdo = new PDO('mysql:host=tfb-database;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass');
|
|
|
|
|
|
# inclue the ActiveRecord library
|
|
# inclue the ActiveRecord library
|
|
-require_once 'vendor/php-activerecord/php-activerecord/ActiveRecord.php';
|
|
|
|
|
|
+require 'vendor/php-activerecord/php-activerecord/ActiveRecord.php';
|
|
|
|
|
|
ActiveRecord\Connection::$PDO_OPTIONS[PDO::ATTR_PERSISTENT] = true;
|
|
ActiveRecord\Connection::$PDO_OPTIONS[PDO::ATTR_PERSISTENT] = true;
|
|
-ActiveRecord\Config::initialize(function($cfg)
|
|
|
|
-{
|
|
|
|
- $cfg->set_model_directory('models');
|
|
|
|
- $cfg->set_connections(array('development' =>
|
|
|
|
- 'mysql://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world'));
|
|
|
|
|
|
+ActiveRecord\Config::initialize(function ($cfg) {
|
|
|
|
+ $cfg->set_model_directory('models');
|
|
|
|
+ $cfg->set_connections(['development' =>
|
|
|
|
+ 'mysql://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world']);
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+if (! isset($_GET['queries'])) {
|
|
|
|
+ echo json_encode(World::find_by_id(mt_rand(1, 10000))->to_array());
|
|
|
|
+ return;
|
|
|
|
+}
|
|
|
|
+
|
|
// Read number of queries to run from URL parameter
|
|
// Read number of queries to run from URL parameter
|
|
$query_count = 1;
|
|
$query_count = 1;
|
|
-$query_param = isset($_GET['queries']);
|
|
|
|
-if ($query_param && $_GET['queries'] > 0) {
|
|
|
|
|
|
+if ($_GET['queries'] > 1) {
|
|
$query_count = $_GET['queries'] > 500 ? 500 : $_GET['queries'];
|
|
$query_count = $_GET['queries'] > 500 ? 500 : $_GET['queries'];
|
|
}
|
|
}
|
|
-
|
|
|
|
// Create an array with the response string.
|
|
// Create an array with the response string.
|
|
-$arr = array();
|
|
|
|
-
|
|
|
|
|
|
+$arr = [];
|
|
// For each query, store the result set values in the response array
|
|
// For each query, store the result set values in the response array
|
|
-$query_counter = $query_count;
|
|
|
|
-while (0 < $query_counter--) {
|
|
|
|
- // Choose a random row
|
|
|
|
- // http://www.php.net/mt_rand
|
|
|
|
- $id = mt_rand(1, 10000);
|
|
|
|
-
|
|
|
|
- $world = World::find_by_id($id);
|
|
|
|
-
|
|
|
|
- // Store result in array.
|
|
|
|
- $arr[] = $world->to_array();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-if ($query_count === 1 && !$query_param) {
|
|
|
|
- $arr = $arr[0];
|
|
|
|
|
|
+while (0 < $query_count--) {
|
|
|
|
+ // Store result in array.
|
|
|
|
+ $arr[] = World::find_by_id(mt_rand(1, 10000))->to_array();
|
|
}
|
|
}
|
|
|
|
|
|
// Use the PHP standard JSON encoder.
|
|
// Use the PHP standard JSON encoder.
|