stat() public static method

Gets stat() information
public static stat ( string $path, callable $cb, integer $pri = EIO_PRI_DEFAULT ) : resource | true
$path string Path
$cb callable Callback
$pri integer Priority
return resource | true
示例#1
0
 /**
  * Constructor.
  * @return void
  */
 public function init()
 {
     if (!isset($this->attrs->server['FR_PATH'])) {
         $this->status(404);
         $this->finish();
         return;
     }
     $job = new \PHPDaemon\Core\ComplexJob(function ($job) {
         $this->wakeup();
     });
     $this->job = $job;
     $this->sleep(5, true);
     $this->attrs->server['FR_PATH'] = \PHPDaemon\FS\FileSystem::sanitizePath($this->attrs->server['FR_PATH']);
     $job('stat', function ($name, $job) {
         /** @var \PHPDaemon\Core\ComplexJob $job */
         \PHPDaemon\FS\FileSystem::stat($this->attrs->server['FR_PATH'], function ($path, $stat) use($job) {
             if ($stat === -1) {
                 $this->fileNotFound();
                 $job->setResult('stat', false);
                 return;
             }
             if ($stat['type'] === 'd') {
                 if (!\PHPDaemon\FS\FileSystem::$supported) {
                     $this->file(rtrim($path, '/') . '/index.html');
                 } else {
                     $job('readdir', function ($name, $job) use($path) {
                         /** @var \PHPDaemon\Core\ComplexJob $job */
                         \PHPDaemon\FS\FileSystem::readdir(rtrim($path, '/'), function ($path, $dir) use($job) {
                             $found = false;
                             if (is_array($dir)) {
                                 foreach ($dir['dents'] as $file) {
                                     if ($file['type'] === \EIO_DT_REG) {
                                         // is file
                                         if (in_array($file['name'], $this->appInstance->indexFiles)) {
                                             $this->file($path . '/' . $file['name']);
                                             $found = true;
                                             break;
                                         }
                                     }
                                 }
                             }
                             if (!$found) {
                                 if (isset($this->attrs->server['FR_AUTOINDEX']) && $this->attrs->server['FR_AUTOINDEX']) {
                                     $this->autoindex($path, $dir);
                                 } else {
                                     $this->fileNotFound();
                                 }
                             }
                             $job->setResult('readdir');
                         }, \EIO_READDIR_STAT_ORDER | \EIO_READDIR_DENTS);
                     });
                 }
             } elseif ($stat['type'] === 'f') {
                 $this->file($path);
             }
             $job->setResult('stat', $stat);
         });
     });
     $job();
 }
示例#2
0
 /**
  * Manager constructor.
  * @param $path
  */
 public function __construct($path, $threadsNum)
 {
     $this->threadsNum = $threadsNum;
     $this->path = $path;
     $this->queue = new StackCallbacks();
     $this->reloadCheckTimer = setTimeout(function ($ev) {
         FileSystem::stat($this->path, function ($path, $stat) {
             if (!$stat) {
                 $this->stop();
                 $this->free();
             }
             if ($this->reloadCheckLastModified >= $stat['mtime']) {
                 return;
             }
             $this->reloadCheckLastModified = $stat['mtime'];
             $this->stop();
             $this->start();
         });
         $ev->timeout(static::RELOAD_CHECK_INTERVAL);
     }, 1);
 }