简体   繁体   中英

json_encode slow

When I am getting 3 records from MySQL and exporting to json with json_encode the php file is loading 0.5 seconds, but when I am getting and exporting 6 records then it is loading 15 seconds. I found that when I will comment json_encode then php file is loading 0.5 seconds with no matter if I am getting 3, 6, 12 or more records, so the problem is somerwhere with json_encode. Is it any possibility to export those 6 recordes to json faster?

One record contain 12 rows with approximatelly 500 characters per record.

One record from 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"]

a bit of php code:

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);

Always check your PHP and MySQL version and settings, there might be something wrong inthere like wrong collation settings. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM