PHPDaemon\FS\FileSystem::readfile PHP Method

readfile() public static method

Reads whole file
public static readfile ( string $path, callable $cb, integer $pri = EIO_PRI_DEFAULT ) : resource | true
$path string Path
$cb callable Callback (Path, Contents)
$pri integer Priority
return resource | true
    public static function readfile($path, $cb, $pri = EIO_PRI_DEFAULT)
    {
        $cb = CallbackWrapper::forceWrap($cb);
        if (!FileSystem::$supported) {
            $cb($path, file_get_contents($path));
            return true;
        }
        return FileSystem::open($path, 'r!', function ($file) use($path, $cb, $pri) {
            if (!$file) {
                $cb($path, false);
                return;
            }
            $file->readAll($cb, $pri);
        }, null, $pri);
    }

Usage Example

 public function init()
 {
     $req = $this;
     $this->sleep(1, true);
     \PHPDaemon\FS\FileSystem::readfile('/etc/filesystems', function ($file, $data) use($req) {
         $req->fileData = $data;
         $req->wakeup();
     });
 }
All Usage Examples Of PHPDaemon\FS\FileSystem::readfile