Created
July 10, 2017 15:10
-
-
Save benagricola/24c1f983f8f350338ce9b887691bc855 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How not to do streaming file reads if you value not making your PHP processes hotloop forever.