BenchAction.class.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. class BenchAction extends Action {
  3. public function rawjson() {
  4. header('Content-type: application/json');
  5. die(json_encode(array('message' => 'Hello World!')));
  6. }
  7. public function rawdb() {
  8. $query_count = (int) $this->_request('queries');
  9. if (0 >= $query_count) {
  10. $query_count = 1;
  11. } elseif (500 < $query_count) {
  12. $query_count = 500;
  13. }
  14. $arr = array();
  15. $World = M('World');
  16. while (0 < $query_count--) {
  17. $id = mt_rand(1, 10000);
  18. $d = $World->find($id);
  19. $arr[] = $d;
  20. }
  21. header('Content-type: application/json');
  22. die(json_encode($arr));
  23. }
  24. public function rawfortunes() {
  25. $Fortunes = M('Fortune');
  26. $data = $Fortunes->select();
  27. $data[] = array(
  28. 'id' => 0,
  29. 'message' => 'Additional fortune added at request time.'
  30. );
  31. usort($data, function($left, $right) {
  32. if ($left['message'] === $right['message']) {
  33. return 0;
  34. } else if ($left['message'] > $right['message']) {
  35. return 1;
  36. } else {
  37. return -1;
  38. }
  39. });
  40. $this->data = $data;
  41. $this->display();
  42. }
  43. }