PHP script that reports progress to Client

∥☆過路亽.° 提交于 2019-12-11 04:07:59

问题


I'm writing a PHP script that does a lot of repetitive work, and when the client executes it, I'd like it to send back HTML in some way, dynamically, as it completes tasks. (without AJAX?) How can this be done?


回答1:


You can flush the output buffer, using flush();

So something like:

taskOne();
echo 'Task one finished';
flush();
...

Hope this helps.




回答2:


Maybe you can use refresh-meta tag, or HTTP header, like this:

header("Refresh: 3; URL=http://www.some.org/some.html");

The browser will then refresh after 3 seconds. If you ask me, this can be kinda anying =) It would be much nicer to inclide an AJAX solution, but it will at least work without too much JavaScript work.




回答3:


You're better off just polling the server via ajax. Set up a script that can monitor your running tasks and poll that. That way the users's browser isn't always in loading mode, and they can go away from the page and come back if they want.




回答4:


Then you'd need to refresh the site, since PHP only runs on each page request.



来源:https://stackoverflow.com/questions/863268/php-script-that-reports-progress-to-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!