doudao3170 2017-04-08 22:59
浏览 64

优化highstock sql的加载时间

I'm using highstock to virtualize some weather data stored in a continuously expanding MySQL database. As the database is getting bigger, the website loading times increased quite a bit. At first I was glad that I've got highstock working as I'm not really into JavaScript and PHP but now I'm looking for a way to improve the loading times.

Right now I'm using 4 different series to show temperatur, humidity, luminance and soil humidity. To import the data I'm using one php script for each series as the last code shows. I don't know how to use only one php script to pass all data over at once neither if that would save any time. But it is definetly the php scripts that take the longest as running them independently takes some time.

Preview Chart

My index.html: https://pastebin.com/KUZfbLjC (there are some strange spaces/tabs that are not in the original file for some reason)

sql_temperature.php:

if (date("I")) {$offset = 7200;} #Offset for daylight saving time
else {$offset = 3600;}

$pdo = new PDO('mysql:host=localhost;dbname=***', '***', '***');

$sql = "select UNIX_TIMESTAMP(Timestamp), Temperature from sensors";
foreach ($pdo->query($sql) as $row) {
   $datetime = ($row[0] + $offset) * 1000;
   $data[] = array((float)$datetime,(float) $row[1]);
}

echo json_encode($data);

So if there is anything to optimize here please let me know.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 Python安装cvxpy库出问题
    • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
    • ¥15 python天天向上类似问题,但没有清零
    • ¥30 3天&7天&&15天&销量如何统计同一行
    • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
    • ¥15 C#调用python代码(python带有库)
    • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
    • ¥15 活动选择题。最多可以参加几个项目?
    • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
    • ¥15 vs2019中数据导出问题