PHP - determine how many bytes sent via http

Is it possible in PHP to get the number of bytes transferred to the client? For example, if I am outputting a 10 megabyte file, is there a way to find out if all 10 MB were sent to the client or to check if the client interrupted part of the transfer? I know that Apache will register this later, but I would like to access data in PHP.

+6
php byte file-transfer
source share
2 answers

Take a look at ignore_user_abort and connection_abort .

+13
source

Here is what I ended up doing (thanks to Gumbo):

 ignore_user_abort(true); $handle = fopen($file_path, 'r'); while ( ! feof($handle)) { echo fread($handle, 4096); if (connection_aborted()) { $transfer_success = false; $bytes_transferred = ftell($handle); break; } } fclose($handle); 
+11
source

All Articles