php - PHP7 cron architecture for MySQL
问题描述
I have some php pages that have lots of queries on them. Everything works correctly, but it takes ages to load the pages due to very large data sets (tens of thousand of rows with compound queries etc.)
I realised I have to optimise this and take it from 30 secs load time to almost 3-4 seconds.
I did some reading on cron job scheduling, and understood how to do it, but I have no idea what the architecture should be in case of a lot of queries.
Example of query in html:
<span class="text-muted my-1">Total count of records time</span>
<hr>
<?php
$select_query = "SELECT SUM(rectime / 3600) AS numberOfHours FROM inf_times";
$result = mysqli_query ($conn, $select_query);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo ceil($row['numberOfHours']) . " hours";
}
}
?>
How do I turn this into a cron job (say a cron job that runs every minute)?
My idea
I want to display the results of the last cron job that ran, so obviously it's a good idea to have variables for the things I'm displaying in a separate PHP file. These should get updated every minute, but how?
解决方案
推荐阅读
- java - 这是通过kafka生产者读取消息并将其推送到主题的正确方法吗
- regex - 如何在包含源代码的目录中列出所有以“U_”开头的单词
- angular - Angular 4自定义验证器不适用于选择标签
- java - 一个动作的多个 Java 使用者
- java - 生成具有更新的 JUnit 依赖项并以 Java 8 为目标的 Maven Java 项目?
- javascript - 在 nodejs 路由中导入模块
- javascript - 给定一个表示层次结构的数组,在JS中输出数据成树形
- node.js - Elasticsearch关键字+范围查询(V-6.2)
- javascript - Three.js - 禁用沿 x、y 和 z 轴的 3d 对象平移
- jquery - 循环内的大文件上的 jQuery load() 会使浏览器无响应。怎么修?