index.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. # Turn off 'beautiful' column names (converting tables names from camelCase to snake_case).
  14. RedBean_OODBBean::setFlagBeautifulColumnNames(false);
  15. R::setup('mysql:host=127.0.0.1;dbname=hello_world','benchmarkdbuser','benchmarkdbpass');
  16. R::freeze(true);
  17. /**
  18. * Step 2: Instantiate a Slim application
  19. *
  20. * This example instantiates a Slim application using
  21. * its default settings. However, you will usually configure
  22. * your Slim application now by passing an associative array
  23. * of setting names and values into the application constructor.
  24. */
  25. $app = new \Slim\Slim();
  26. /**
  27. * Step 3: Define the Slim application routes
  28. *
  29. * Here we define several Slim application routes that respond
  30. * to appropriate HTTP request methods. In this example, the second
  31. * argument for `Slim::get`, `Slim::post`, `Slim::put`, and `Slim::delete`
  32. * is an anonymous function.
  33. */
  34. $app->get('/json', function () use($app) {
  35. $app->contentType('application/json');
  36. echo json_encode(array('message' => 'Hello, World!'));
  37. });
  38. $app->get('/db', function () use($app) {
  39. $queries = ($app->request()->get('queries') !== null)
  40. ? $app->request()->get('queries')
  41. : 1;
  42. $worlds = array();
  43. for ($i = 0; $i < $queries; ++$i) {
  44. $worlds[] = R::load('World', mt_rand(1, 10000))->export();
  45. }
  46. $app->contentType('application/json');
  47. echo json_encode($worlds);
  48. });
  49. /**
  50. * Step 4: Run the Slim application
  51. *
  52. * This method should be called last. This executes the Slim application
  53. * and returns the HTTP response to the HTTP client.
  54. */
  55. $app->run();