문제

I have a web page which uses php exec() to run a perl script which writes to a file. The problem is, the perl script takes a long time to execute, and I would like to start showing the results on the webpage before it finally returns. I currently have exec() displaying the content of the file it writes to in a div which gets reloaded every 3 seconds.

I can't seem to figure out how to get the page to start loading before the perl script finishes. Does anyone have an idea on how this might be accomplished?

도움이 되었습니까?

해결책

Run your perlscript from a different php-file in an iframe. This way it will execute the script but you do not need to wait for it to succeed. If the perlscript prints to your file before it is ready, you even could read those lines in your mainpage and show first results.

다른 팁

See Randal's definitive article on the topic: Watching long processes through CGI. You'll need to adapt the Perl CGI script he uses to watch the traceroute output and do something similar using PHP. The essential idea is:

the browser hits the form, and the user fills out that form; the browser submits the form, and after verifying good infomation, the response forks to run the task, and redirects the browser back with a session key; the forked process runs the task, taking output as it arrives and updates a cache value, flagging when it is complete; the CGI script pulls from the cache, and displays it, sending a refresh as long as the data is not complete.

How can you close out the page's body tag and send it if you don't have all the content?

You need to rearchitect it as an asynchronout load, where the page serves up javascript that calls a server url that returns partial results, appends that to the DOM, and continues calling the server url to get more partial results.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top