douhuangjian9627 2013-07-28 08:30
浏览 96

如何告诉PHP仅在一段时间内等待SQL查询?

I have a mysqli_query() in a PHP script which usually takes about 10 ms to finish. However, sometimes it takes about 5000 ms. This query isn't important for the site to function properly, i.e. it can be ignored if it takes for more than 10 ms.

Is this possible to do?

Something like:

<?php

// microtime here is X
$query = mysqli_query($connection, "(do something)");
// if difference between time now and previous time is bigger than 10 ms,
// skip waiting for the $query result and go on

?>

If anything like this is possible, can we also cancel the running query, so that MySQL server knows we don't want the result anymore and stops processing it?

  • 写回答

1条回答 默认 最新

  • douyu5775 2013-07-28 08:43
    关注

    Since the query is not sensitive, you should cache the results instead of hitting the database each time.

    PHP provides mysqlnd-qc the (qc is for query cache) which works with APC and friends to cache the results of MySQL queries.

    The other option is to cache the template instead. Smarty has this included. This means you render the page once, and then only render it after a certain fixed time.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?