Skip to content

Instantly share code, notes, and snippets.

@benagricola
Created July 10, 2017 15:10
Show Gist options
  • Save benagricola/24c1f983f8f350338ce9b887691bc855 to your computer and use it in GitHub Desktop.
Save benagricola/24c1f983f8f350338ce9b887691bc855 to your computer and use it in GitHub Desktop.
<?php
/**
* Class X_Io_File
*/
class X_Io_File extends Varien_Io_File {
/**
* @return void
*/
public function rewind() {
rewind($this->_streamHandler);
}
/**
* @return string
*/
public function getFileName() {
return $this->_streamFileName;
}
/**
* @param $fileUrl
*/
static public function batchReturn($fileUrl)
{
// This prevents timeouts for bigger files
$bytesBatch = 1024 * 8;
@set_time_limit(0);
$file = @fopen($fileUrl, 'rb');
while (!feof($file)) {
echo @fread($file, $bytesBatch);
ob_flush();
flush();
}
}
}
@benagricola
Copy link
Author

How not to do streaming file reads if you value not making your PHP processes hotloop forever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment