Browse Source

Merge pull request #2175 from knewmanTE/add-missing-php-tests

Add missing php tests
A Shawn Bandy 8 years ago
parent
commit
690c3dab49
33 changed files with 508 additions and 128 deletions
  1. 1 1
      frameworks/PHP/cygnite-php-framework/deploy/nginx.conf
  2. 24 0
      frameworks/PHP/laravel/app/routes.php
  3. 4 73
      frameworks/PHP/lithium/app/config/routes.php
  4. 43 1
      frameworks/PHP/lithium/app/controllers/BenchController.php
  5. 12 0
      frameworks/PHP/lithium/app/models/Fortune.php
  6. 0 0
      frameworks/PHP/lithium/app/resources/tmp/cache/templates/blank
  7. 12 0
      frameworks/PHP/lithium/app/views/bench/fortunes.html.php
  8. 3 0
      frameworks/PHP/lithium/benchmark_config.json
  9. 8 0
      frameworks/PHP/slim/benchmark_config.json
  10. 2 1
      frameworks/PHP/slim/composer.json
  11. 57 11
      frameworks/PHP/slim/index.php
  12. 18 0
      frameworks/PHP/slim/templates/fortunes.php
  13. 13 1
      frameworks/PHP/symfony2-stripped/app/config/routing.yml
  14. 3 0
      frameworks/PHP/symfony2-stripped/benchmark_config.json
  15. 46 1
      frameworks/PHP/symfony2-stripped/src/Skamander/BenchmarkBundle/Controller/BenchController.php
  16. 13 1
      frameworks/PHP/symfony2/app/config/routing.yml
  17. 5 0
      frameworks/PHP/symfony2/benchmark_config.json
  18. 46 1
      frameworks/PHP/symfony2/src/Skamander/BenchmarkBundle/Controller/BenchController.php
  19. 37 0
      frameworks/PHP/yaf/app/modules/Bench/controllers/Raw.php
  20. 2 0
      frameworks/PHP/yaf/benchmark_config.json
  21. 3 1
      frameworks/PHP/yii2/benchmark_config.json
  22. 2 0
      frameworks/PHP/zend/benchmark_config.json
  23. 37 1
      frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Controller/BenchController.php
  24. 0 23
      frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Controller/JsonController.php
  25. 26 9
      frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Module.php
  26. 3 3
      frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/ServiceFactory/BenchControllerServiceFactory.php
  27. 15 0
      frameworks/PHP/zend1/application/controllers/FortunesController.php
  28. 12 0
      frameworks/PHP/zend1/application/controllers/PlaintextController.php
  29. 26 0
      frameworks/PHP/zend1/application/controllers/UpdatesController.php
  30. 10 0
      frameworks/PHP/zend1/application/models/Fortune.php
  31. 10 0
      frameworks/PHP/zend1/application/models/FortuneRow.php
  32. 12 0
      frameworks/PHP/zend1/application/views/scripts/fortunes/index.phtml
  33. 3 0
      frameworks/PHP/zend1/benchmark_config.json

+ 1 - 1
frameworks/PHP/cygnite-php-framework/deploy/nginx.conf

@@ -32,7 +32,7 @@ http {
     keepalive_timeout  65;
 
     #gzip  on;
-    
+
     upstream fastcgi_backend {
         server 127.0.0.1:9001;
     }

+ 24 - 0
frameworks/PHP/laravel/app/routes.php

@@ -45,4 +45,28 @@ Route::get('/db', function()
     return Response::json(DB::table('World')->find(mt_rand(1, 10000)));
 });
 
+Route::get('/updates', function()
+{
+    $queries = Input::get('queries', 1);
+
+    if (!is_numeric($queries) || $queries <= 1) {
+    	$queries = 1;
+    }
+    else if ($queries > 500) {
+        $queries = 500;
+    }
+
+    $worlds = array();
+
+    for($i = 0; $i < $queries; $i++) {
+        $id = mt_rand(1, 10000);
+        $random_number = mt_rand(1, 10000);
+        $world = DB::table('World')->find($id);
+        $world->randomNumber = $random_number;
+        DB::table('World')->where('id', $id)->update(['randomNumber' => $random_number]);
+        $worlds[] = $world;
+    }
+    return Response::json($worlds);
+});
+
 Route::get('/fortunes', 'BenchController@fortunes');

+ 4 - 73
frameworks/PHP/lithium/app/config/routes.php

@@ -19,79 +19,10 @@
 use lithium\net\http\Router;
 use lithium\core\Environment;
 
-/**
- * With globalization enabled a localized route is configured by connecting a
- * continuation route. Once the route has been connected, all the other
- * application routes become localized and may now carry a locale.
- *
- * Requests to routes like `/en/posts/edit/1138` or `/fr/posts/edit/1138` will
- * carry a locale, while `/posts/edit/1138` keeps on working as it did before.
- */
-if ($locales = Environment::get('locales')) {
-	$template = '/{:locale:' . join('|', array_keys($locales)) . '}/{:args}';
-	Router::connect($template, array(), array('continue' => true));
-}
-
-/**
- * Here, we are connecting `'/'` (the base path) to controller called `'Pages'`,
- * its action called `view()`, and we pass a param to select the view file
- * to use (in this case, `/views/pages/home.html.php`; see `app\controllers\PagesController`
- * for details).
- *
- * @see app\controllers\PagesController
- */
 Router::connect('/json', 'Bench::json');
-
-/**
- * Connect the rest of `PagesController`'s URLs. This will route URLs like `/pages/about` to
- * `PagesController`, rendering `/views/pages/about.html.php` as a static page.
- */
 Router::connect('/db/{:queries}', array('Bench::db', 'queries' => 1));
+Router::connect('/plaintext', 'Bench::plaintext');
+Router::connect('/update/{:queries}', array('Bench::update', 'queries' => 1));
+Router::connect('/fortunes', 'Bench::fortunes');
 
-/**
- * Add the testing routes. These routes are only connected in non-production environments, and allow
- * browser-based access to the test suite for running unit and integration tests for the Lithium
- * core, as well as your own application and any other loaded plugins or frameworks. Browse to
- * [http://path/to/app/test](/test) to run tests.
- */
-if (!Environment::is('production')) {
-	Router::connect('/test/{:args}', array('controller' => 'lithium\test\Controller'));
-	Router::connect('/test', array('controller' => 'lithium\test\Controller'));
-}
-
-/**
- * ### Database object routes
- *
- * The routes below are used primarily for accessing database objects, where `{:id}` corresponds to
- * the primary key of the database object, and can be accessed in the controller as
- * `$this->request->id`.
- *
- * If you're using a relational database, such as MySQL, SQLite or Postgres, where the primary key
- * is an integer, uncomment the routes below to enable URLs like `/posts/edit/1138`,
- * `/posts/view/1138.json`, etc.
- */
-// Router::connect('/{:controller}/{:action}/{:id:\d+}.{:type}', array('id' => null));
-// Router::connect('/{:controller}/{:action}/{:id:\d+}');
-
-/**
- * If you're using a document-oriented database, such as CouchDB or MongoDB, or another type of
- * database which uses 24-character hexidecimal values as primary keys, uncomment the routes below.
- */
-// Router::connect('/{:controller}/{:action}/{:id:[0-9a-f]{24}}.{:type}', array('id' => null));
-// Router::connect('/{:controller}/{:action}/{:id:[0-9a-f]{24}}');
-
-/**
- * Finally, connect the default route. This route acts as a catch-all, intercepting requests in the
- * following forms:
- *
- * - `/foo/bar`: Routes to `FooController::bar()` with no parameters passed.
- * - `/foo/bar/param1/param2`: Routes to `FooController::bar('param1, 'param2')`.
- * - `/foo`: Routes to `FooController::index()`, since `'index'` is assumed to be the action if none
- *   is otherwise specified.
- *
- * In almost all cases, custom routes should be added above this one, since route-matching works in
- * a top-down fashion.
- */
-Router::connect('/{:controller}/{:action}/{:args}');
-
-?>
+?>

+ 43 - 1
frameworks/PHP/lithium/app/controllers/BenchController.php

@@ -4,9 +4,14 @@ namespace app\controllers;
 
 use  lithium\action\Controller;
 use  app\models\World;
+use  app\models\Fortune;
 
 class BenchController extends Controller {
 
+    public function plaintext() {
+      return $this->render(array('text' => 'Hello, World!'));
+    }
+
     public function json() {
         return $this->render(array(
             'json' => array('message' => 'Hello, World!')
@@ -17,6 +22,7 @@ class BenchController extends Controller {
         $queries = isset($this->request->query['queries'])
             ? $this->request->query['queries']
             : 1;
+        $queries = min(max(1, $queries), 500);
         $worlds = array();
 
         for ($i = 0; $i < $queries; ++$i) {
@@ -31,4 +37,40 @@ class BenchController extends Controller {
             'json' => $worlds
         ));
     }
-}
+
+    public function update() {
+      $queries = isset($this->request->query['queries'])
+          ? $this->request->query['queries']
+          : 1;
+      $queries = min(max(1, $queries), 500);
+      $worlds = array();
+
+      for ($i = 0; $i < $queries; ++$i) {
+          $id = mt_rand(1, 10000);
+          $random_number = mt_rand(1, 10000);
+          $world = World::first(array(
+              'conditions' => array(
+                  'id' => $id
+              )
+          ));
+          $world->randomNumber = $random_number;
+          $world->save();
+          $worlds[] = $world;
+      }
+
+      return $this->render(array(
+          'json' => $worlds
+      ));
+    }
+
+    public function fortunes() {
+        $fortunes = Fortune::find('all')->to('array');
+        $fortunes[] = array('id' => 0, 'message' => 'Additional fortune added at request time.');
+        usort($fortunes, function($left, $right) {
+           return strcmp($left['message'], $right['message']);
+        });
+
+        $this->set(['fortunes' => $fortunes]);
+        return $this->render(array('layout' => false));
+    }
+}

+ 12 - 0
frameworks/PHP/lithium/app/models/Fortune.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace app\models;
+
+use \lithium\data\Model;
+
+class Fortune extends Model {
+    // stop lithium from pluralizing the table name
+    protected $_meta = array(
+        'source' => 'Fortune'
+    );
+}

+ 0 - 0
frameworks/PHP/lithium/app/resources/tmp/cache/templates/blank


+ 12 - 0
frameworks/PHP/lithium/app/views/bench/fortunes.html.php

@@ -0,0 +1,12 @@
+<!doctype html>
+<html>
+<head><title>Fortunes</title></head>
+<body>
+<table>
+<tr><th>id</th><th>message</th></tr>
+<?php foreach($fortunes as $fortune) { ?>
+  <tr><td><?php echo $fortune['id']; ?></td><td><?php echo $h($fortune['message']); ?></td></tr>
+<?php } ?>
+</table>
+</body>
+</html>

+ 3 - 0
frameworks/PHP/lithium/benchmark_config.json

@@ -3,9 +3,12 @@
   "tests": [{
     "default": {
       "setup_file": "setup",
+      "plaintext_url": "/plaintext",
       "json_url": "/json",
       "db_url": "/db",
+      "update_url": "/update?queries=",
       "query_url": "/db?queries=",
+      "fortune_url": "/fortunes",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Fullstack",

+ 8 - 0
frameworks/PHP/slim/benchmark_config.json

@@ -3,9 +3,12 @@
   "tests": [{
     "default": {
       "setup_file": "setup",
+      "plaintext_url": "/plaintext",
       "json_url": "/json",
       "db_url": "/db",
       "query_url": "/dbs?queries=",
+      "update_url": "/updates?queries=",
+      "fortune_url": "/fortunes",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Micro",
@@ -23,9 +26,11 @@
     },
     "hhvm": {
       "setup_file": "setup_hhvm",
+      "plaintext_url": "/plaintext",
       "json_url": "/json",
       "db_url": "/db",
       "query_url": "/dbs?queries=",
+      "update_url": "/updates?queries=",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Micro",
@@ -43,9 +48,12 @@
     },
     "php5": {
       "setup_file": "setup_php5",
+      "plaintext_url": "/plaintext",
       "json_url": "/json",
       "db_url": "/db",
       "query_url": "/dbs?queries=",
+      "update_url": "/updates?queries=",
+      "fortune_url": "/fortunes",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Micro",

+ 2 - 1
frameworks/PHP/slim/composer.json

@@ -1,5 +1,6 @@
 {
     "require": {
-        "slim/slim": "3.3.0"
+        "slim/slim": "3.3.0",
+        "slim/php-view": "2.1.0" 
     }
 }

+ 57 - 11
frameworks/PHP/slim/index.php

@@ -4,8 +4,25 @@ error_reporting(-1);
 require_once __DIR__.'/vendor/autoload.php';
 
 $app = new \Slim\App;
+$container = $app->getContainer();
+$container['db'] = function ($c) {
+  $db = $c['settings']['db'];
+  $pdo = new PDO('mysql:host=localhost;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass');
+  $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+  $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
+  return $pdo;
+};
+$container['view'] = new \Slim\Views\PhpRenderer("templates/");
+
+// Test 1: Plaintext
+$app->get('/plaintext', function ($request, $response) {
+    return $response
+        ->write('Hello, World!')
+        ->withHeader('Content-Type', 'text/plain')
+        ;
+});
 
-// Test 1: JSON serialization
+// Test 2: JSON serialization
 $app->get('/json', function ($request, $response) {
     return $response
         ->withJson(array('message' => 'Hello, World!'))
@@ -13,16 +30,8 @@ $app->get('/json', function ($request, $response) {
         ;
 });
 
-$container = $app->getContainer();
-$container['db'] = function ($c) {
-    $db = $c['settings']['db'];
-    $pdo = new PDO('mysql:host=localhost;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass');
-    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
-    return $pdo;
-};
 
-// Test 2: Single database query
+// Test 3: Single database query
 $app->get('/db', function ($request, $response) {
     $sth = $this->db->prepare('SELECT * FROM World WHERE id = ?');
     $sth->execute(array(mt_rand(1, 10000)));
@@ -37,7 +46,7 @@ $app->get('/db', function ($request, $response) {
         ;
 });
 
-// Test 3: Multiple database queries
+// Test 4: Multiple database queries
 $app->get('/dbs', function ($request, $response) {
     $queries = max(1, min($request->getParam('queries'), 500));
 
@@ -58,4 +67,41 @@ $app->get('/dbs', function ($request, $response) {
         ;
 });
 
+// Test 5: Updates
+$app->get('/updates', function ($request, $response) {
+    $queries = max(1, min($request->getParam('queries'), 500));
+
+    $sth = $this->db->prepare('SELECT * FROM World WHERE id = ?');
+    $worlds = array();
+    for ($i = 0; $i < $queries; ++$i) {
+        $id = mt_rand(1, 10000);
+        $random_number = mt_rand(1, 10000);
+        $sth->execute(array($id));
+        $world = $sth->fetch();
+        # Cast fields to int so they don't get wrapped with quotes
+        $world['id'] = (int) $world['id'];
+        $world['randomNumber'] = $random_number;
+        $update_query = $this->db->prepare('UPDATE World SET randomNumber = ? WHERE id = ?');
+        $update_query->execute(array($world['randomNumber'], $world['id']));
+        $worlds[] = $world;
+    }
+
+    return $response
+        ->withJson($worlds)
+        ->withHeader('Content-Type', 'application/json') // fixes utf-8 warning
+        ;
+});
+
+// Test 6: Fortunes
+$app->get('/fortunes', function ($request, $response) {
+    $sth = $this->db->prepare('SELECT * FROM Fortune');
+    $sth->execute();
+    $fortunes = $sth->fetchAll();
+    array_push($fortunes, array('id'=> 0, 'message' => 'Additional fortune added at request time.'));
+    usort($fortunes, function($left, $right) {
+        return strcmp($left['message'], $right['message']);
+    });
+    return $this->view->render($response, "fortunes.php", ["fortunes" => $fortunes]);
+});
+
 $app->run();

+ 18 - 0
frameworks/PHP/slim/templates/fortunes.php

@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+  <head><title>Fortunes</title></head>
+  <body>
+    <table>
+        <tr>
+            <th>id</th>
+            <th>message</th>
+        </tr>
+        <?php foreach($data['fortunes'] as $fortune){ ?>
+            <tr>
+                <td><?php echo $fortune['id']; ?></td>
+                <td><?php echo htmlspecialchars($fortune['message']); ?></td>
+            </tr>
+        <?php } ?>
+    </table>
+  </body>
+</html>

+ 13 - 1
frameworks/PHP/symfony2-stripped/app/config/routing.yml

@@ -1,3 +1,7 @@
+_plaintext:
+    pattern:  /plaintext
+    defaults: { _controller: SkamanderBenchmarkBundle:Bench:plaintext }
+
 _json:
     pattern:  /json
     defaults: { _controller: SkamanderBenchmarkBundle:Bench:json }
@@ -10,6 +14,14 @@ _dbRaw:
     pattern:  /db-raw
     defaults: { _controller: SkamanderBenchmarkBundle:Bench:dbRaw }
 
+_update:
+    pattern:  /update
+    defaults: { _controller: SkamanderBenchmarkBundle:Bench:update }
+
+_updateRaw:
+    pattern:  /update-raw
+    defaults: { _controller: SkamanderBenchmarkBundle:Bench:updateRaw }
+
 _fortunes:
     pattern:  /fortunes
     defaults: { _controller: SkamanderBenchmarkBundle:Bench:fortunes }
@@ -20,4 +32,4 @@ _fortunesPhp:
 
 _fortunesRaw:
     pattern:  /fortunes-raw
-    defaults: { _controller: SkamanderBenchmarkBundle:Bench:fortunesRaw }
+    defaults: { _controller: SkamanderBenchmarkBundle:Bench:fortunesRaw }

+ 3 - 0
frameworks/PHP/symfony2-stripped/benchmark_config.json

@@ -3,8 +3,10 @@
   "tests": [{
     "default": {
       "setup_file": "setup",
+      "plaintext_url": "/plaintext",
       "json_url": "/json",
       "db_url": "/db",
+      "update_url": "/update?queries=",
       "query_url": "/db?queries=",
       "fortune_url": "/fortunes",
       "port": 8080,
@@ -43,6 +45,7 @@
     "raw": {
       "setup_file": "setup",
       "db_url": "/db-raw",
+      "update_url": "/update-raw?queries=",
       "query_url": "/db-raw?queries=",
       "fortune_url": "/fortunes-raw",
       "port": 8080,

+ 46 - 1
frameworks/PHP/symfony2-stripped/src/Skamander/BenchmarkBundle/Controller/BenchController.php

@@ -11,6 +11,11 @@ use Skamander\BenchmarkBundle\Entity\Fortune;
 class BenchController extends Controller
 {
 
+    public function plaintextAction()
+    {
+      return new Response("Hello, World!", 200, array('Content-Type' => 'text/plain'));
+    }
+
     public function jsonAction()
     {
         return new JsonResponse(array('message' => 'Hello, World!'));
@@ -49,7 +54,7 @@ class BenchController extends Controller
         for($i = 0; $i < $queries; ++$i) {
             $worlds[] =  $conn->fetchAssoc('SELECT * FROM World WHERE id = ?', array(mt_rand(1, 10000)));
         }
-        
+
         if ($queries == 1) {
             $worlds = $worlds[0];
         }
@@ -57,6 +62,46 @@ class BenchController extends Controller
         return new JsonResponse($worlds);
     }
 
+    public function updateAction(Request $request)
+    {
+      $queries = $request->query->getInt('queries', 1);
+      $queries = min(500, max(1, $queries));
+
+      $worlds = array();
+      $em = $this->getDoctrine()->getManager();
+      $repo = $this->getDoctrine()
+          ->getRepository('SkamanderBenchmarkBundle:World');
+
+      for ($i = 0; $i < $queries; ++$i) {
+        $world = $repo->find(mt_rand(1, 10000));
+        $random_number = mt_rand(1, 10000);
+        $world->setRandomNumber($random_number);
+        $em->persist($world);
+        $worlds[] =  $world;
+      }
+
+      $em->flush();
+      return new JsonResponse($worlds);
+    }
+
+    public function updateRawAction(Request $request)
+    {
+      $queries = $request->query->getInt('queries', 1);
+      $queries = min(500, max(1, $queries));
+
+      $worlds = array();
+      $conn = $this->get('database_connection');
+
+      for($i = 0; $i < $queries; ++$i) {
+          $id = mt_rand(1, 10000);
+          $random_number = mt_rand(1, 10000);
+          $conn->executeUpdate('UPDATE World SET randomNumber=? WHERE id=?', array($random_number, $id));
+          $worlds[] =  array('id' => $id, 'randomNumber' => $random_number);
+      }
+
+      return new JsonResponse($worlds);
+    }
+
     public function fortunesAction()
     {
         $repo = $this->getDoctrine()

+ 13 - 1
frameworks/PHP/symfony2/app/config/routing.yml

@@ -1,3 +1,7 @@
+_plaintext:
+    pattern:  /plaintext
+    defaults: { _controller: SkamanderBenchmarkBundle:Bench:plaintext }
+
 _json:
     pattern:  /json
     defaults: { _controller: SkamanderBenchmarkBundle:Bench:json }
@@ -10,6 +14,14 @@ _dbRaw:
     pattern:  /db-raw
     defaults: { _controller: SkamanderBenchmarkBundle:Bench:dbRaw }
 
+_update:
+    pattern:  /update
+    defaults: { _controller: SkamanderBenchmarkBundle:Bench:update }
+
+_updateRaw:
+    pattern:  /update-raw
+    defaults: { _controller: SkamanderBenchmarkBundle:Bench:updateRaw }
+
 _fortunes:
     pattern:  /fortunes
     defaults: { _controller: SkamanderBenchmarkBundle:Bench:fortunes }
@@ -20,4 +32,4 @@ _fortunesPhp:
 
 _fortunesRaw:
     pattern:  /fortunes-raw
-    defaults: { _controller: SkamanderBenchmarkBundle:Bench:fortunesRaw }
+    defaults: { _controller: SkamanderBenchmarkBundle:Bench:fortunesRaw }

+ 5 - 0
frameworks/PHP/symfony2/benchmark_config.json

@@ -3,8 +3,10 @@
   "tests": [{
     "default": {
       "setup_file": "setup",
+      "plaintext_url": "/plaintext",
       "json_url": "/json",
       "db_url": "/db",
+      "update_url": "/update?queries=",
       "query_url": "/db?queries=",
       "fortune_url": "/fortunes",
       "port": 8080,
@@ -43,6 +45,7 @@
     "raw": {
       "setup_file": "setup",
       "db_url": "/db-raw",
+      "update_url": "/update-raw?queries=",
       "query_url": "/db-raw?queries=",
       "fortune_url": "/fortunes-raw",
       "port": 8080,
@@ -62,7 +65,9 @@
     },
     "hhvm": {
       "setup_file": "setup_hhvm",
+      "plaintext_url": "/plaintext",
       "json_url": "/json",
+      "update_url": "/update?queries=",
       "db_url": "/db",
       "query_url": "/db?queries=",
       "fortune_url": "/fortunes",

+ 46 - 1
frameworks/PHP/symfony2/src/Skamander/BenchmarkBundle/Controller/BenchController.php

@@ -11,6 +11,11 @@ use Skamander\BenchmarkBundle\Entity\Fortune;
 class BenchController extends Controller
 {
 
+    public function plaintextAction()
+    {
+      return new Response("Hello, World!", 200, array('Content-Type' => 'text/plain'));
+    }
+
     public function jsonAction()
     {
         return new JsonResponse(array('message' => 'Hello, World!'));
@@ -49,7 +54,7 @@ class BenchController extends Controller
         for($i = 0; $i < $queries; ++$i) {
             $worlds[] =  $conn->fetchAssoc('SELECT * FROM World WHERE id = ?', array(mt_rand(1, 10000)));
         }
-        
+
         if ($queries == 1) {
             $worlds = $worlds[0];
         }
@@ -57,6 +62,46 @@ class BenchController extends Controller
         return new JsonResponse($worlds);
     }
 
+    public function updateAction(Request $request)
+    {
+      $queries = $request->query->getInt('queries', 1);
+      $queries = min(500, max(1, $queries));
+
+      $worlds = array();
+      $em = $this->getDoctrine()->getManager();
+      $repo = $this->getDoctrine()
+          ->getRepository('SkamanderBenchmarkBundle:World');
+
+      for ($i = 0; $i < $queries; ++$i) {
+        $world = $repo->find(mt_rand(1, 10000));
+        $random_number = mt_rand(1, 10000);
+        $world->setRandomNumber($random_number);
+        $em->persist($world);
+        $worlds[] =  $world;
+      }
+
+      $em->flush();
+      return new JsonResponse($worlds);
+    }
+
+    public function updateRawAction(Request $request)
+    {
+      $queries = $request->query->getInt('queries', 1);
+      $queries = min(500, max(1, $queries));
+
+      $worlds = array();
+      $conn = $this->get('database_connection');
+
+      for($i = 0; $i < $queries; ++$i) {
+          $id = mt_rand(1, 10000);
+          $random_number = mt_rand(1, 10000);
+          $conn->executeUpdate('UPDATE World SET randomNumber=? WHERE id=?', array($random_number, $id));
+          $worlds[] =  array('id' => $id, 'randomNumber' => $random_number);
+      }
+
+      return new JsonResponse($worlds);
+    }
+
     public function fortunesAction()
     {
         $repo = $this->getDoctrine()

+ 37 - 0
frameworks/PHP/yaf/app/modules/Bench/controllers/Raw.php

@@ -5,6 +5,12 @@ use Yaf\Controller_Abstract as AbstractController;
 class RawController extends AbstractController
 {
 
+    public function plaintextAction ()
+    {
+      header('Content-Type: text/plain');
+      die("Hello, World!");
+    }
+
     public function jsonAction ()
     {
         header('Content-type: application/json');
@@ -43,6 +49,37 @@ class RawController extends AbstractController
         die(json_encode($arr));
     }
 
+    public function updatesAction ()
+    {
+      $dbh = DatabaseManager::getInstance()->getConnection();
+
+      $query_count = (int) $this->getRequest()->get('queries', 1);
+
+      if (0 >= $query_count) {
+          $query_count = 1;
+      } elseif (500 < $query_count) {
+          $query_count = 500;
+      }
+
+      $arr = array();
+      $id = mt_rand(1, 10000);
+      $random_number = mt_rand(1, 10000);
+
+      $statement = $dbh->prepare('UPDATE `World` SET `randomNumber` = :random_number WHERE `id` = :id');
+      $statement->bindParam(':id', $id, \PDO::PARAM_INT);
+      $statement->bindParam(':random_number', $random_number, \PDO::PARAM_INT);
+
+      while (0 < $query_count--) {
+          $statement->execute();
+          $arr[] = array('id' => $id, 'randomNumber' => $random_number);
+          $random_number = mt_rand(1, 10000);
+          $id = mt_rand(1, 10000);
+      }
+
+      header('Content-type: application/json');
+      die(json_encode($arr));
+    }
+
     public function fortunesAction ()
     {
         $view = $this->getView();

+ 2 - 0
frameworks/PHP/yaf/benchmark_config.json

@@ -3,8 +3,10 @@
   "tests": [{
     "default": {
       "setup_file": "setup",
+      "plaintext_url": "/bench/raw/plaintext",
       "json_url": "/bench/raw/json",
       "db_url": "/bench/raw/db",
+      "update_url": "/bench/raw/updates?queries=",
       "query_url": "/bench/raw/db?queries=",
       "fortune_url": "/bench/raw/fortunes",
       "port": 8080,

+ 3 - 1
frameworks/PHP/yii2/benchmark_config.json

@@ -3,6 +3,7 @@
   "tests": [{
     "default": {
       "setup_file": "setup",
+      "plaintext_url": "/site/plaintext",
       "json_url": "/site/json",
       "db_url": "/site/db",
       "query_url": "/site/db?queries=",
@@ -25,6 +26,7 @@
     },
     "hhvm": {
       "setup_file": "setup_hhvm",
+      "plaintext_url": "/site/plaintext",
       "json_url": "/site/json",
       "db_url": "/site/db",
       "query_url": "/site/db?queries=",
@@ -46,4 +48,4 @@
       "versus": "php5"
     }
   }]
-}
+}

+ 2 - 0
frameworks/PHP/zend/benchmark_config.json

@@ -3,8 +3,10 @@
   "tests": [{
     "default": {
       "setup_file": "setup",
+      "plaintext_url": "/plaintext",
       "json_url": "/json",
       "db_url": "/db",
+      "update_url": "/update?queries=",
       "query_url": "/db-multi?queries=",
       "port": 8080,
       "approach": "Realistic",

+ 37 - 1
frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Controller/DbController.php → frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Controller/BenchController.php

@@ -5,6 +5,7 @@ namespace FrameworkBenchmarks\Controller;
 use Zend\Mvc\Controller\AbstractActionController;
 use Zend\Stdlib\ArrayUtils;
 use Zend\View\Model\JsonModel;
+use Zend\Http\Headers;
 use Zend\Db\TableGateway\TableGateway;
 
 /**
@@ -13,7 +14,7 @@ use Zend\Db\TableGateway\TableGateway;
  * @author Marco Pivetta <[email protected]>
  * @link   http://www.techempower.com/benchmarks
  */
-class DbController extends AbstractActionController
+class BenchController extends AbstractActionController
 {
     /**
      * @var \Zend\Db\TableGateway\TableGateway
@@ -28,6 +29,11 @@ class DbController extends AbstractActionController
         $this->tableGateway = $tableGateway;
     }
 
+    public function jsonAction()
+    {
+        return new JsonModel(array('message' => 'Hello, World!'));
+    }
+
     /**
      * @return \Zend\View\Model\JsonModel
      */
@@ -63,4 +69,34 @@ class DbController extends AbstractActionController
 
         return new JsonModel($worlds);
     }
+
+    public function updateAction()
+    {
+      $request = $this->getRequest();
+      $queries = (int) $request->getQuery('queries', 1);
+      $queries = max(1, $queries);
+      $queries = min(500, $queries);
+
+      $worlds  = array();
+
+      for ($i = 0; $i < $queries; $i += 1) {
+          $id = mt_rand(1, 10000);
+          foreach ($this->tableGateway->select(array('id' => $id)) as $found) {
+              $random_number = mt_rand(1, 10000);
+              $found->randomNumber = $random_number;
+              $this->tableGateway->update(array('randomNumber' => $random_number), array('id' => $id));
+              $worlds[] = $found;
+          }
+      }
+
+      return new JsonModel($worlds);
+    }
+
+    public function plaintextAction()
+    {
+      $response = $this->getResponse();
+      $response->getHeaders()->addHeaders(array('COntent-Type' => 'text/plain'));
+      $response->setContent('Hello, World!');
+      return $response;
+    }
 }

+ 0 - 23
frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Controller/JsonController.php

@@ -1,23 +0,0 @@
-<?php
-
-namespace FrameworkBenchmarks\Controller;
-
-use Zend\Mvc\Controller\AbstractActionController;
-use Zend\View\Model\JsonModel;
-
-/**
- * Controller that produces the `hello world` json for the benchmarks of FrameworkBenchmarks
- *
- * @author Marco Pivetta <[email protected]>
- * @link   http://www.techempower.com/benchmarks
- */
-class JsonController extends AbstractActionController
-{
-    /**
-     * @return \Zend\View\Model\JsonModel
-     */
-    public function indexAction()
-    {
-        return new JsonModel(array('message' => 'Hello, World!'));
-    }
-}

+ 26 - 9
frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Module.php

@@ -18,13 +18,23 @@ class Module
         return array(
             'router' => array(
                 'routes' => array(
+                    'plaintext' => array(
+                      'type' => 'Zend\Mvc\Router\Http\Literal',
+                      'options' => array(
+                          'route' => '/plaintext',
+                          'defaults' => array(
+                              'controller' => 'FrameworkBenchmarks\Controller\BenchController',
+                              'action' => 'plaintext',
+                          ),
+                      ),
+                    ),
                     'json' => array(
                         'type' => 'Zend\Mvc\Router\Http\Literal',
                         'options' => array(
                             'route' => '/json',
                             'defaults' => array(
-                                'controller' => 'FrameworkBenchmarks\Controller\JsonController',
-                                'action' => 'index',
+                                'controller' => 'FrameworkBenchmarks\Controller\BenchController',
+                                'action' => 'json',
                             ),
                         ),
                     ),
@@ -33,7 +43,7 @@ class Module
                         'options' => array(
                             'route' => '/db',
                             'defaults' => array(
-                                'controller' => 'FrameworkBenchmarks\Controller\DbController',
+                                'controller' => 'FrameworkBenchmarks\Controller\BenchController',
                                 'action' => 'db',
                             ),
                         ),
@@ -43,11 +53,21 @@ class Module
                         'options' => array(
                             'route' => '/db-multi',
                             'defaults' => array(
-                                'controller' => 'FrameworkBenchmarks\Controller\DbController',
+                                'controller' => 'FrameworkBenchmarks\Controller\BenchController',
                                 'action' => 'db-multi',
                             ),
                         ),
                     ),
+                    'update' => array(
+                        'type' => 'Zend\Mvc\Router\Http\Literal',
+                        'options' => array(
+                            'route' => '/update',
+                            'defaults' => array(
+                                'controller' => 'FrameworkBenchmarks\Controller\BenchController',
+                                'action' => 'update',
+                            ),
+                        ),
+                    ),
                 ),
             ),
             'db' => array(
@@ -55,12 +75,9 @@ class Module
                 'dsn'    => 'mysql:dbname=hello_world;host=localhost',
             ),
             'controllers' => array(
-                'invokables' => array(
-                    'FrameworkBenchmarks\Controller\JsonController' => 'FrameworkBenchmarks\Controller\JsonController',
-                ),
                 'factories' => array(
-                    'FrameworkBenchmarks\Controller\DbController'
-                        => 'FrameworkBenchmarks\ServiceFactory\DbControllerServiceFactory'
+                    'FrameworkBenchmarks\Controller\BenchController'
+                        => 'FrameworkBenchmarks\ServiceFactory\BenchControllerServiceFactory'
                 ),
             ),
             'service_manager' => array(

+ 3 - 3
frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/ServiceFactory/DbControllerServiceFactory.php → frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/ServiceFactory/BenchControllerServiceFactory.php

@@ -9,7 +9,7 @@
 
 namespace FrameworkBenchmarks\ServiceFactory;
 
-use FrameworkBenchmarks\Controller\DbController;
+use FrameworkBenchmarks\Controller\BenchController;
 use FrameworkBenchmarks\Entity\World;
 use Zend\Db\ResultSet\ResultSet;
 use Zend\Db\TableGateway\TableGateway;
@@ -22,7 +22,7 @@ use Zend\ServiceManager\ServiceLocatorInterface;
  * @author Marco Pivetta <[email protected]>
  * @link   http://www.techempower.com/benchmarks
  */
-class DbControllerServiceFactory implements FactoryInterface
+class BenchControllerServiceFactory implements FactoryInterface
 {
     /**
      * {@inheritDoc}
@@ -38,6 +38,6 @@ class DbControllerServiceFactory implements FactoryInterface
 
         $resultSetPrototype->setArrayObjectPrototype(new World());
 
-        return new DbController(new TableGateway('World', $dbAdapter, null, $resultSetPrototype));
+        return new BenchController(new TableGateway('World', $dbAdapter, null, $resultSetPrototype));
     }
 }

+ 15 - 0
frameworks/PHP/zend1/application/controllers/FortunesController.php

@@ -0,0 +1,15 @@
+<?php
+
+class FortunesController extends Zend_Controller_Action
+{
+    public function indexAction()
+    {
+        $table = new Model_Fortune();
+        $fortunes = $table->fetchAll()->toArray();
+        array_push($fortunes, array('id'=> 0, 'message' => 'Additional fortune added at request time.'));
+        usort($fortunes, function($left, $right) {
+            return strcmp($left['message'], $right['message']);
+        });
+        $this->view->fortunes = $fortunes;
+    }
+}

+ 12 - 0
frameworks/PHP/zend1/application/controllers/PlaintextController.php

@@ -0,0 +1,12 @@
+<?php
+
+class PlaintextController extends Zend_Controller_Action
+{
+    public function indexAction()
+    {
+      $this->_helper->viewRenderer->setNoRender(true);
+      $this->getResponse()
+           ->setHeader('Content-Type', 'text/plain')
+           ->appendBody('Hello, World!');
+    }
+}

+ 26 - 0
frameworks/PHP/zend1/application/controllers/UpdatesController.php

@@ -0,0 +1,26 @@
+<?php
+
+class UpdatesController extends Zend_Controller_Action
+{
+    public function indexAction()
+    {
+        $queries = (int) $this->getParam('queries', 1);
+        $queries = max(1, $queries);
+        $queries = min(500, $queries);
+
+        $table = new Model_World();
+
+        $worlds = array();
+        for ($i = 0; $i < $queries; $i += 1) {
+            $id = mt_rand(1, 10000);
+            $random_number = mt_rand(1, 10000);
+            $world = $table->fetchRow(array('id = ?' => $id))->toArray();
+            $world['randomNumber'] = $random_number;
+            $where = $table->getAdapter()->quoteInto('id = ?', $id);
+            $table->update(array('randomNumber' => $random_number), $where);
+            $worlds[] = $world;
+        }
+
+        $this->_helper->json->sendJson($worlds);
+    }
+}

+ 10 - 0
frameworks/PHP/zend1/application/models/Fortune.php

@@ -0,0 +1,10 @@
+<?php
+class Model_Fortune extends Zend_Db_Table_Abstract {
+	protected $_name = 'Fortune';
+
+	public function __construct() {
+		parent::__construct(array(
+			'rowClass' => 'Model_FortuneRow'
+		));
+	}
+}

+ 10 - 0
frameworks/PHP/zend1/application/models/FortuneRow.php

@@ -0,0 +1,10 @@
+<?php
+class Model_FortuneRow extends Zend_Db_Table_Row_Abstract {
+	public function __construct($config = array()) {
+		if ( array_key_exists('data', $config) ) {
+			$config['data']['id'] = (int) $config['data']['id'];
+			$config['data']['message'] = (int) $config['data']['message'];
+		}
+		parent::__construct($config);
+	}
+}

+ 12 - 0
frameworks/PHP/zend1/application/views/scripts/fortunes/index.phtml

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head><title>Fortunes</title></head>
+<body>
+<table>
+<tr><th>id</th><th>message</th></tr>
+<?php foreach($this->fortunes as $fortune){ ?>
+<tr><td><?php echo $fortune['id']; ?></td><td><?php echo $this->escape($fortune['message']); ?></td></tr>
+<?php } ?>
+</table>
+</body>
+</html>

+ 3 - 0
frameworks/PHP/zend1/benchmark_config.json

@@ -3,9 +3,12 @@
   "tests": [{
     "default": {
       "setup_file": "setup",
+      "plaintext_url": "/plaintext",
       "json_url": "/json",
       "db_url": "/db",
       "query_url": "/db-multi?queries=",
+      "update_url": "/updates?queries=",
+      "fortune_url": "/fortunes",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Fullstack",