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.

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

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样