doufu9947 2012-04-03 19:24
浏览 64
已采纳

“实时”响应耗时的PHP脚本?

Many times i run time consuming PHP scripts that echo status updates like 'batch 1 finished', 'batch 2 finished' etc.

i've noticed that sometimes the server responds in a 'live' manner and you can see these status updates as the 'jobs' finish, printed on the browser.

But in other times you have to wait for the script to end, and the browser displays all the status updates at once.

When does the first happen? Is it the browser? Is it PHP setup? The way the script is coded?

  • 写回答

1条回答 默认 最新

  • dongpu9852 2012-04-03 19:27
    关注

    You can use ob_flush to send current output to the browser.

    Or the process may be run as a background process, and communicate via a fast process, like writing database records, and updated via an AJAX request.

    If you have a particular use case, let us know what it is and perhaps someone can advise what would be the best approach for you. (Largely it depends on what sort of server you're running; shared hosts for example often won't run background processes).

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

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算