12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- use Symfony\Component\HttpFoundation\JsonResponse;
- use Symfony\Component\HttpFoundation\Request;
- error_reporting(-1);
- require_once __DIR__.'/../vendor/autoload.php';
- $app = new Silex\Application();
- $app->register(new Silex\Provider\DoctrineServiceProvider(), array(
- 'db.options' => array(
- 'driver' => 'pdo_mysql',
- 'host' => '192.168.100.102',
- 'dbname' => 'hello_world',
- 'user' => 'benchmarkdbuser',
- 'password' => 'benchmarkdbpass',
- ),
- ));
- $app->get('/json', function() {
- return new JsonResponse(array("message" => "Hello World!"));
- });
- $app->get('/db', function(Request $request) use ($app) {
- $queries = $request->query->getInt('queries', 1);
- // possibility for micro enhancement could be the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php
- $worlds = array();
- for($i = 0; $i < $queries; ++$i) {
- $worlds[] = $app['db']->fetchAssoc('SELECT * FROM World WHERE id = ?', array(mt_rand(1, 10000)));
- }
- return new JsonResponse($worlds);
- });
- $app->run();
|