如何在 PHP 中实时实现 For 循环
我想制作一个实时给出结果的脚本。
在我的脚本中它有 3 个步骤。
第一步是从网页中获取所有链接。(我使用 pregmatch_all 函数,因为我需要的所有链接都以相同的域开始 http: //example.com/docs/* 并从 http://test.com/page/* )
第二步我必须从所有人那里获取直接链接链接(例如 http://files.example.com/files/* 来自 http://example.com/docs/* )
第三步 将该文件上传到第三方网站并获取从那里上传链接。
最后我添加了一个名为获取页面范围(如 '1|5' )的函数,因此脚本上传来自 http 的所有链接://test.com/page/1/ 到 http://test.com/page/ 5/ .
我已经完成了脚本,它运行正常,但它在全部完成后显示结果,但我想要一个实时结果,例如脚本已抓取一个链接并用它执行所有步骤,并在浏览器上显示该结果链接,然后依此类推,我的意思是实时解决方案 。
我该怎么做,我使用了 for 循环但没有实时结果。
I want to Make a Script which give result realtime .
In My Script it have 3 steps .
1st step was to grab all links from a webpage .(i use pregmatch_all function coz all links i need are started with same domain http://example.com/docs/* and grab from http://test.com/page/* )
2nd step i have to grab direct link from all links (like htp://files.example.com/files/* from
http://example.com/docs/* )
3rd step Upload that file to and third party site and get the upload link from there .
lastly i added a function named which get the page ranges (like '1|5' ) so script upload all links from http://test.com/page/1/ to http://test.com/page/5/ .
I have done the scipt it was alo running ok but it shows result after all completed but i want a realtime result like script have grabed one link and do all steps with it and show that reult link on browser and then so on i mean a realtime solution .
How can i do that i used for loop but no real time result .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Flush() 会帮助你。
Flush() would help you.
使用ajax。 (在后台运行脚本并轮询当前状态)
http://jqueryui.com/demos/progressbar/
http://api.jquery.com/get
use ajax. (run script in background and poll for current state)
http://jqueryui.com/demos/progressbar/
http://api.jquery.com/get
如果您认真从事 PHP Web 开发,那么阅读输出缓冲、输出刷新和相关主题绝对是个好主意。
Reading up on output buffering, output flushing and related topics is definitely a good idea if you are serious about PHP web development.