json_encode慢

时间:2013-02-10 16:13:45

标签: php json

当我从MySQL获取3条记录并使用json_encode导出到json时,php文件加载0.5秒,但是当我获取并导出6条记录时,则加载15秒。我发现当我评论json_encode然后php文件加载0.5秒,无论我是否获得3,6,12或更多记录,所以问题是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);

1 个答案:

答案 0 :(得分:1)

始终检查您的PHP和MySQL版本和设置,可能有一些错误,如错误的排序规则设置。 :)