简体   繁体   English

json_encode慢

[英]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. 当我从MySQL获取3条记录并使用json_encode导出到json时,php文件加载了0.5秒,但是当我获取并导出6条记录时,它加载了15秒。 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. 我发现,当我要注释json_encode时,php文件将加载0.5秒,而不管我是否获得3、6、12或更多记录,因此json_encode出现了问题。 Is it any possibility to export those 6 recordes to json faster? 有可能更快地将这6条记录导出到json吗?

One record contain 12 rows with approximatelly 500 characters per record. 一条记录包含12行,每条记录大约包含500个字符。

One record from json: 来自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: 一点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);

Always check your PHP and MySQL version and settings, there might be something wrong inthere like wrong collation settings. 经常检查您的PHP和MySQL版本和设置,可能有错误的排序规则设置。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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