@@ -428,6 +428,7 @@ public function readfile($path) {
428428 $ chunkSize = 524288 ; // 512 kB chunks
429429 while (!feof ($ handle )) {
430430 echo fread ($ handle , $ chunkSize );
431+ $ this ->checkConnectionStatus ();
431432 flush ();
432433 }
433434 fclose ($ handle );
@@ -480,6 +481,7 @@ public function readfilePart($path, $from, $to) {
480481 $ len = $ chunkSize ;
481482 }
482483 echo fread ($ handle , $ len );
484+ $ this ->checkConnectionStatus ();
483485 flush ();
484486 }
485487 return ftell ($ handle ) - $ from ;
@@ -490,6 +492,14 @@ public function readfilePart($path, $from, $to) {
490492 return false ;
491493 }
492494
495+
496+ private function checkConnectionStatus (): void {
497+ $ connectionStatus = \connection_status ();
498+ if ($ connectionStatus !== 0 ) {
499+ throw new \RuntimeException ("Connection lost. Status: $ connectionStatus " );
500+ }
501+ }
502+
493503 /**
494504 * @param string $path
495505 * @return mixed
@@ -1053,7 +1063,6 @@ public function toTmpFile($path) {
10531063 public function fromTmpFile ($ tmpFile , $ path ) {
10541064 $ this ->assertPathLength ($ path );
10551065 if (Filesystem::isValidPath ($ path )) {
1056-
10571066 // Get directory that the file is going into
10581067 $ filePath = dirname ($ path );
10591068
@@ -1809,7 +1818,6 @@ private function assertPathLength($path) {
18091818 * @return boolean
18101819 */
18111820 private function targetIsNotShared (IStorage $ targetStorage , string $ targetInternalPath ) {
1812-
18131821 // note: cannot use the view because the target is already locked
18141822 $ fileId = (int )$ targetStorage ->getCache ()->getId ($ targetInternalPath );
18151823 if ($ fileId === -1 ) {
0 commit comments