• http.Fetch read data before EOF?
    5 replies, posted
Hello, I'm using http.Fetch to call a PHP web-page which performs an action. This action can take anywhere between a few seconds, and a couple of minutes to complete. While the PHP action is running, it "echo"'s the percentage of completion. However, I only receive the data once the PHP file has read its end. How can I get the data before the PHP file ends, so that I could correctly draw a progress bar (via Derma)? Thanks
What I would personally do in this situation, is have your "action" run in the background, and call that php page every second or so to find the progress.
not sure how well it'll work, but [url=https://en.wikipedia.org/wiki/Chunked_transfer_encoding]chunked responses[/url] might be worth a shot
[QUOTE=PortalGod;48120815]not sure how well it'll work, but [url=https://en.wikipedia.org/wiki/Chunked_transfer_encoding]chunked responses[/url] might be worth a shot[/QUOTE] Just took a look at chunked responses. Looks like they could be what I need, however I setup my PHP script to do chunked responses, and http.Fetch simply returns all of the data at once when it finishes. Looks like http.Fetch will only ready the data when it gets ALL of the data. Darn.
[QUOTE=KFC Chiken;48120906]Just took a look at chunked responses. Looks like they could be what I need, however I setup my PHP script to do chunked responses, and http.Fetch simply returns all of the data at once when it finishes.[/QUOTE] As far as I know, PHP only sends stuff when you flush the output buffer, which is only done at the end of the file if you don't do it manually. The gmod http.Fetch function also only calls the callback when it has received all the data. The only way I can think of doing it is polling your PHP script every couple seconds, or writing your own HTTP client that calls a callback everytime it receives a packet of information.
Quick and dirty way to get percentage is to make the php script write a file with the percentage every few seconds and just querying the file.
Sorry, you need to Log In to post a reply to this thread.