当数据变大时,php json无法返回

问题描述 投票:0回答:1

它适用于较少的行,但在结果增加到8000行后不返回任何内容

<?php
  require("db_config.php");
  $con=mysqli_connect($DB_SERVER,$DB_USER,$DB_PASSWORD,$DB_DATABASE);
  if (mysqli_connect_errno($con))
  {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  $sql = "SELECT stop_id, stop_code, stop_name from stops";
  $result = mysqli_query($con, $sql);
  echo $sql . mysqli_num_rows($result);
  if(mysqli_num_rows($result) > 0) {
    $response["stopnames"] = array();
    while ($row = mysqli_fetch_array($result)) {
            $item = array();
            $item["stop_id"] = $row["stop_id"];
            $item["stop_code"] = $row["stop_code"];
            $item["stop_name"] = $row["stop_name"];
            // push ordered items into response array 
            array_push($response["stopnames"], $item);
    }
    // success
    $response["success"] = 1;
    $response["msg"] = $sql;
  }
  else
  {
      // order is empty
      $response["success"] = 0;
      $response["msg"] = $sql;
  }

  // echoing JSON response
  echo json_encode($response);
  mysqli_close($con);
?>

结果:来自stops7618的SELECT stop_id,stop_code,stop_name表示,已提取了大约7618行,但没有返回结果对于结果中的一些较少的行,它可以正常工作

php json
1个回答
0
投票

由于最大执行时间或内存限制,您的脚本可能会终止。

在开始添加

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

在echo json_encode($ response)之后添加类似的内容

echo 'Stoped';

并检查它是否会输出

© www.soinside.com 2019 - 2024. All rights reserved.