|
Posted by Gordon Burditt on 10/09/17 11:36
>Here is an advanced PHP question. Can anyone think of a way to detect
>the number of bytes written to output when a script is aborted?
What are you going to use that information for?
>I am sending a large file to the client, and I want to record how many
>bytes are actually sent.
Bytes sent != bytes received. Why is there a problem with the
script aborting? Modem drops carrier? Spontaneous Windows reboot?
Browser crash?
>I can detect abort of the script using a
>shutdown handler. In the shutdown handler, I tried ob_get_length, but
>it returns false. I tried to read the server's log file, but it is does
>not contain the information until the script fully quits. I tried to
>use fwrite to php://output, and then get the bytes written return value.
>However, if the script aborts in the middle of the write, then bytes
>written is never returned.
If one end of a TCP connection quietly goes away, you might be
able to write 64k more bytes before you realize it has gone away.
>The only thing that worked was writing one byte at a time using
>fread/fwrite. But this also made the processor load 100% and download
>speed very slow (700KB/sec versus 24MB/sec on localhost using wget).
What do you intend to use this for? If you're trying to figure out
where to restart sending the file, it won't be accurate.
Gordon L. Burditt
[Back to original message]
|