Bench.php 891 B

1234567891011121314151617181920212223242526272829303132
  1. <?php defined('SYSPATH') OR die('No Direct Script Access');
  2. Class Controller_Bench extends Controller
  3. {
  4. public function action_json()
  5. {
  6. $this->response
  7. ->headers(array('Content-Type' => 'application/json'))
  8. ->body(json_encode(array("message" => "Hello World!")));
  9. }
  10. public function action_db()
  11. {
  12. $queries = $this->request->param('queries');
  13. $queries = (isset($queries) && is_numeric($queries))
  14. ? $queries
  15. : 1;
  16. $worlds = array();
  17. for ($i = 0; $i < $queries; ++$i) {
  18. $worlds[] = DB::select()->from('World')
  19. ->where('id', '=', mt_rand(1, 10000))
  20. ->execute()
  21. ->current();
  22. }
  23. $this->response
  24. ->headers(array('Content-Type' => 'application/json'))
  25. ->body(json_encode($worlds));
  26. }
  27. }