新足迹

 找回密码
 注册

精华好帖回顾

· 闲聊Trust (2015-6-15) fubao · Q&A各类问题大汇总,解答你绝大部分困惑! (2005-1-7) horseanddragon
· 汽车被别人追尾--FIX 和保险CLAIM 的进程! (2008-8-26) jialiren · HOLDEN ASTRA RS-V车评 (附全系价格) (2017-10-18) 黑山老妖
Advertisement
Advertisement
查看: 4572|回复: 2

Regarding reading data from mysql or json file [复制链接]

发表于 2017-12-12 13:22 |显示全部楼层
此文章由 pureboy 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 pureboy 所有!转贴必须注明作者、出处和本声明,并保持内容完整
I have a web site to load the images with GPS exif information and add the markers on the google map to generate the routes.

I have a routes consisted with 88 images which means need to read the 88 record from the mysql database.

the sql is like

select lat,lng, item_name, Originaldatetime, image_path,street_name from maps where map_id=xxxx order by UTC.

At beging, I mixed up the php code to read all records from the mysql table with while loop and the javascript to show the maps together.

The page stacked in blank page waiting the php to read all the records from the table.
To improve the user experience, I taken away to code the read the data from the mysql db, and leave the javascript only looks after rendering the maps and html elements.

php script do all the heavy lifting job by connect to the db and read all the data from table and read all record into arrays in while loop. once it array generated,

header("Content-type:application/json");
$myjson = fopen("maps/$user/$map_id.json", "w") or die("Unable to open file!");
fwrite($myjson, json_encode(array($arrLat,$arrLng,$arrDT,$arrTimeDiff,$arrSPD,$full_path,$arr_item_name,$width,$height,$arr_street)));
        fclose($myjson);

php has export the arrays into json encoder in 2 way, firstly, it echo to the javascript ,2ndly, it export the json file on the server disk.

This provide the options on how javascipt the read the json data.

In javascript:

1.                //$.getJSON('map_data.php?map_id='+map_id, function (data) {
2.              $.getJSON('maps/1511215176230503.json', function (data) {

2 ways to read the json data, 1st option is simply wait for respond from the php to read all the data from the mysql db, and loop through each element of the json file.
2ndly, read the json from the json file which is pre generated by php code.

to read data from the table cost around 7018 ms while read from json file is 328 ms.

It suggested that developer need to export json to files read from my sql data. the benefit is if you need to read the json data more than once, only the first read need to consume a lot of time.

It improve the user experience.

有图有真相


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
Advertisement
Advertisement

发表于 2017-12-17 00:03 来自手机 |显示全部楼层
此文章由 jin-1234 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 jin-1234 所有!转贴必须注明作者、出处和本声明,并保持内容完整
如果为了省重复性操作的网络时间,生成json文件的话。你的程序需要能够有选择性的更新json内容,否则json数据可能会和数据库的实际数据产生差别。比如你可以让程序每n分钟读取db,刷新json内容

评分

参与人数 1积分 +3 收起 理由
pureboy + 3 感谢你的耐心。

查看全部评分

发表于 2017-12-17 15:44 |显示全部楼层
此文章由 pureboy 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 pureboy 所有!转贴必须注明作者、出处和本声明,并保持内容完整
本帖最后由 pureboy 于 2017-12-17 15:47 编辑
jin-1234 发表于 2017-12-17 00:03
如果为了省重复性操作的网络时间,生成json文件的话。你的程序需要能够有选择性的更新json内容,否则json数 ...


没错,有实时性的问题。
对于相对静态的数据,这方法是是更加适合。

在这个应用里面,主要是读取已经生成的图像地址,图像的GPS信息和时间信息,所以只要一次生成JSON文件就足够了。

谢谢你有耐心看完这对堆砌在一起的文字。

发表回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Advertisement
Advertisement
返回顶部