dongqiangse6623 2016-11-14 12:33
浏览 38

截断并插入问题

I am currently working on a script which has a big database so to decrease load i built a table which contain a data that is updated every minute(CRON PHP FILE).So it works just fine but i am having right now an issue. The code I am using:

$conn->query("TRUNCATE tempo");
 $conn->query("INSERT INTO ....");

and the php file i get the data from the tempo table the problem right now is that when php runs every minute there is a short delay like 1 second between data delete and data insert so in this 1 second the table tempo is empty so every minute i have 1second in which the website just return 0 data (because of the delay). How can I solve this problem ?

  • 写回答

1条回答 默认 最新

  • dpitqpax07626 2016-11-14 13:30
    关注

    If you cannot have any downtime in accessing the data, then have 2 tables with identical structure, I'll refer to them as table_A and table_B. At any time, only one of them should be "live", meaning one will serve all requests for the data. Let's say it is table_A at the moment.

    When you do the import from the cron, then truncate table_B and insert the data into table_B. When the insertion into table_B is done, then mark table_B as the live one and the next import's target should be table_A.

    This way you are not going to have any downtime accessing your data.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度