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 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64