index.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Step 1: Require the Slim Framework
  4. *
  5. * If you are not using Composer, you need to require the
  6. * Slim Framework and register its PSR-0 autoloader.
  7. *
  8. * If you are using Composer, you can skip this step.
  9. */
  10. require 'Slim/Slim.php';
  11. require 'Slim/RedBean/rb.php';
  12. \Slim\Slim::registerAutoloader();
  13. R::setup('mysql:host=localhost;dbname=hello_world','benchmarkdbuser','benchmarkdbpass');
  14. R::freeze(true);
  15. /**
  16. * Step 2: Instantiate a Slim application
  17. *
  18. * This example instantiates a Slim application using
  19. * its default settings. However, you will usually configure
  20. * your Slim application now by passing an associative array
  21. * of setting names and values into the application constructor.
  22. */
  23. $app = new \Slim\Slim();
  24. /**
  25. * Step 3: Define the Slim application routes
  26. *
  27. * Here we define several Slim application routes that respond
  28. * to appropriate HTTP request methods. In this example, the second
  29. * argument for `Slim::get`, `Slim::post`, `Slim::put`, and `Slim::delete`
  30. * is an anonymous function.
  31. */
  32. $app->get('/json', function () use($app) {
  33. $app->contentType('application/json');
  34. echo json_encode(array('message' => 'Hello, World!'));
  35. });
  36. $app->get('/db', function () use($app) {
  37. $queries = ($app->request()->get('queries') !== null)
  38. ? $app->request()->get('queries')
  39. : 1;
  40. $worlds = array();
  41. for ($i = 0; $i < $queries; ++$i) {
  42. $worlds[] = R::load('World', mt_rand(1, 10000))->export();
  43. }
  44. $app->contentType('application/json');
  45. echo json_encode($worlds);
  46. });
  47. /**
  48. * Step 4: Run the Slim application
  49. *
  50. * This method should be called last. This executes the Slim application
  51. * and returns the HTTP response to the HTTP client.
  52. */
  53. $app->run();