PHPDaemon\FS\FileSystem::readfileChunked PHP Method

readfileChunked() public static method

Reads file chunk-by-chunk
public static readfileChunked ( string $path, callable $cb, callable $chunkcb, integer $pri = EIO_PRI_DEFAULT ) : resource
$path string Path
$cb callable Callback (Path, Success)
$chunkcb callable Chunk callback (Path, Chunk)
$pri integer Priority
return resource
    public static function readfileChunked($path, $cb, $chunkcb, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!FileSystem::$supported) {
            $chunkcb($path, $r = readfile($path));
            $cb($r !== false);
            return;
        }
        FileSystem::open($path, 'r!', function ($file) use($path, $cb, $chunkcb, $pri) {
            if (!$file) {
                $cb($path, false);
                return;
            }
            $file->readAllChunked($cb, $chunkcb, $pri);
        }, null, $pri);
    }

Usage Example

Beispiel #1
0
 /**
  * Read request body from the file given in REQUEST_BODY_FILE parameter
  * @return boolean Success
  */
 public function readBodyFile()
 {
     if (!isset($this->attrs->server['REQUEST_BODY_FILE'])) {
         return false;
     }
     FileSystem::readfileChunked($this->attrs->server['REQUEST_BODY_FILE'], function ($file, $success) {
         $this->attrs->inputDone = true;
         if ($this->sleepTime === 0) {
             $this->wakeup();
         }
     }, function ($file, $chunk) {
         // readed chunk
         $this->stdin($chunk);
     });
     return true;
 }