当我从 MySQL 获取 3 条记录并使用 json_encode 导出到 json 时,php 文件正在加载 0.5 秒,但是当我获取并导出 6 条记录时,它正在加载 15 秒。我发现当我评论 json_encode 时,无论我获得 3、6、12 条还是更多记录,php 文件都会加载 0.5 秒,所以问题出在 json_encode 的某个地方。是否有可能更快地将这 6 条记录导出到 json?
一条记录包含 12 行,每条记录大约 500 个字符。
来自 json 的一条记录:
["7","49-z-zamiast-250-z-za-lifting-bez-skalpela-nieinwazyjny-i-bezbolesny-zabieg-na-wybran-parti-twarzy-w-salonie-motylem-jestem-na-warszawskim-bemowie","49 z\u0142 zamiast 250 z\u0142 za lifting bez skalpela - nieinwazyjny i bezbolesny zabieg na wybran\u0105 parti\u0119 twarzy w Salonie \"Motylem Jestem\" na warszawskim Bemowie","49","250","80",148448,"67b9e57e02b409cd60f3f9745b9c9073","80% rabatu - 49-z-zamiast-250-z-za-lifting-","Zdrowie i Uroda","Frupi","Warszawa"]
一些php代码:
while($row=mysql_fetch_assoc($result))
{
$id=$row['id'];
$slug=$row['slug'];
$short_title=$row['deal_save_percent']."% rabatu - ".substr($slug,0,30);
$title=$row['deal_title'];
$price=$row['deal_price'];
$price_old=$row['deal_face_value'];
$discount=$row['deal_save_percent'];
$end_time=$row['deal_oe_end_date']-$ts;
$image_url=md5($row['deal_image_url']);
$category_name=$row['category'];
$website=$row['web_site'];
$city=$row['city'];
$arr[]=array('0'=>$id, '1' => $slug, '2' => $title, '3' => $price, '4' => $price_old, '5' => $discount, '6' => $end_time, '7' => $image_url, '8' => $short_title, '9' => $category_name, '10' => $website, '11' => $city);
}
echo json_encode($arr);