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条回答 默认 最新

    报告相同问题?