ku_controller.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. use Workerman\Protocols\Http;
  3. class KuController extends AppController
  4. {
  5. protected function before_filter()
  6. {
  7. View::select(null, null);
  8. Http::header('Content-Type: application/json');
  9. }
  10. public function index()
  11. {
  12. KuRaw::$random->execute([mt_rand(1, 10000)]);
  13. echo json_encode(KuRaw::$random->fetch());
  14. }
  15. public function query($count = 1)
  16. {
  17. $count = min(max((int) $count, 1), 500);
  18. while ($count--) {
  19. KuRaw::$random->execute([mt_rand(1, 10000)]);
  20. $worlds[] = KuRaw::$random->fetch();
  21. }
  22. echo json_encode($worlds);
  23. }
  24. public function update($count = 1)
  25. {
  26. $count = min(max((int) $count, 1), 500);
  27. while ($count--) {
  28. KuRaw::$random->execute([mt_rand(1, 10000)]);
  29. $row = KuRaw::$random->fetch();
  30. $row['randomNumber'] = mt_rand(1, 10000);
  31. $worlds[] = $row;
  32. }
  33. KuRaw::update($worlds);
  34. echo json_encode($worlds);
  35. }
  36. }