db-eloquent.php 725 B

123456789101112131415161718192021222324252627
  1. <?php
  2. // Set content type
  3. header('Content-type: application/json');
  4. require __DIR__.'/boot-eloquent.php';
  5. if (! isset($_GET['queries'])) {
  6. echo json_encode(World::find(mt_rand(1, 10000)));
  7. return;
  8. }
  9. // Read number of queries to run from URL parameter
  10. $query_count = 1;
  11. if ($_GET['queries'] > 1) {
  12. $query_count = $_GET['queries'] > 500 ? 500 : $_GET['queries'];
  13. }
  14. // Create an array with the response string.
  15. $arr = [];
  16. // For each query, store the result set values in the response array
  17. while ($query_count--) {
  18. // Store result in array.
  19. $arr[] = World::find(mt_rand(1, 10000));
  20. }
  21. // Use the PHP standard JSON encoder.
  22. // http://www.php.net/manual/en/function.json-encode.php
  23. echo json_encode($arr);