index.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. use Symfony\Component\HttpFoundation\JsonResponse;
  3. use Symfony\Component\HttpFoundation\Request;
  4. error_reporting(-1);
  5. require_once __DIR__.'/../vendor/autoload.php';
  6. $app = new Silex\Application();
  7. $app->register(new Silex\Provider\DoctrineServiceProvider(), array(
  8. 'db.options' => array(
  9. 'driver' => 'pdo_mysql',
  10. 'host' => '192.168.100.102',
  11. 'dbname' => 'hello_world',
  12. 'user' => 'benchmarkdbuser',
  13. 'password' => 'benchmarkdbpass',
  14. ),
  15. ));
  16. $app->get('/json', function() {
  17. return new JsonResponse(array("message" => "Hello World!"));
  18. });
  19. $app->get('/db', function(Request $request) use ($app) {
  20. $queries = $request->query->getInt('queries', 1);
  21. // possibility for micro enhancement could be the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php
  22. $worlds = array();
  23. for($i = 0; $i < $queries; ++$i) {
  24. $worlds[] = $app['db']->fetchAssoc('SELECT * FROM World WHERE id = ?', array(mt_rand(1, 10000)));
  25. }
  26. return new JsonResponse($worlds);
  27. });
  28. $app->run();