douxin1884 2014-05-14 09:16
浏览 394
已采纳

如何在PHP中的for循环中使睡眠函数正确响应

I am writing a script that gets an eight digit number then reads it out loud. I want a delay of two seconds between the numbers as they are being read out. The problem is that even after setting the delay with sleep(), all my numbers are read out at once which leads to a summon-like audio that is getting me closer to being the antichrist with every debug. Here is my code. How do i get my loop to execute so that the numbers are read as e.g 2 .... 1 .... 3 .... 4 .... (where .... = 2 seconds.)

for($counter=0; $counter<count($dbId); $counter++)
{
    $fileName = array_search($dbId[$counter], $letterArray);
    echo "<audio src='../resources/audio/mp3/'.$fileName.'.mp3' autoplay></audio>";
    echo time() . "<br />";
    sleep(2);
}
  • 写回答

2条回答 默认 最新

  • dty63504 2014-05-14 09:23
    关注

    You have an incorrect understanding of sleep. Sleep delays the php script, which delays the response from the server, but the resulting webpage that you serve will be exactly the same with or without sleep. It will just take longer to load. You can not control this from php you have to do it on the client somehow. Look at this question for example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错