Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Handles graceful disconnections while streaming

Author Dave Jarvis <email>
Date 2026-02-20 01:10:45 GMT-0800
Commit 9e967c3776d4fc68942a348afa81c32ad6f12228
Parent 4445a2a
git/Git.php
if( $real && strpos( $real, $repo ) === 0 ) {
- $result = readfile( $path ) !== false;
+ $result = $this->streamFileContent( $path );
+ }
+ }
+ }
+
+ return $result;
+ }
+
+ private function streamFileContent( string $path ): bool {
+ $result = false;
+ $handle = fopen( $path, 'rb' );
+
+ if( $handle !== false ) {
+ ignore_user_abort( true );
+ set_time_limit( 0 );
+
+ while( !feof( $handle ) && connection_aborted() === 0 ) {
+ $chunk = fread( $handle, 8192 );
+
+ if( $chunk !== false && $chunk !== '' ) {
+ echo $chunk;
+
+ if( ob_get_level() > 0 ) {
+ ob_flush();
+ }
+
+ flush();
}
}
+
+ $result = connection_aborted() === 0;
+
+ fclose( $handle );
}
Delta 31 lines added, 1 line removed, 30-line increase