dongzha5934 2011-08-23 18:30
浏览 53
已采纳

php usleep同时请求

I've been playing around with the ApacheBench (ab) command line utility but I'm not sure if it's the right tool for what I'm trying to do.

I was running 10 concurrent and 10 requests doing an INSERT into a MySQL table and looking at round(microtime(1) * 10000) to see if I was getting the same values.

I would like to know if using delayed execution usleep() is enough to prevent two simultaneous requests getting the same value on the same box, or is time_sleep_until better.

I know I could set more entropy with uniqid().

So I'm just wondering if using delayed execution will be enough to prevent two exact time stamps.

  • 写回答

1条回答 默认 最新

  • dsrnwngq411594 2011-08-23 19:14
    关注

    So you want to know if round(microtime(1) * 10000) can give duplicate values? Well of course it can, I don't think you need to test for this.

    uniqid is also not guaranteed to be unique, even with more entropy.

    If uniqueness is really important you could always use MySQL with a UNIQUE index to enforce uniqueness.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题