PHPDaemon\Core\Daemon::loadModuleIfAbsent PHP Method

loadModuleIfAbsent() public static method

Load PHP extension (module) if absent
public static loadModuleIfAbsent ( string $mod, string $version = null, string $compare = '>=' ) : boolean
$mod string
$version string
$compare string
return boolean $success
    public static function loadModuleIfAbsent($mod, $version = null, $compare = '>=')
    {
        if (!extension_loaded($mod)) {
            if (!get_cfg_var('enable_dl')) {
                return false;
            }
            if (!@dl(basename($mod) . '.so')) {
                return false;
            }
        }
        if (!$version) {
            return true;
        }
        try {
            $ext = new \ReflectionExtension($mod);
            return version_compare($ext->getVersion(), $version, $compare);
        } catch (\ReflectionException $e) {
            return false;
        }
    }

Usage Example

Example #1
0
 /**
  * Constructor
  */
 public function __construct()
 {
     if (Daemon::loadModuleIfAbsent('inotify')) {
         $this->inotify = inotify_init();
         stream_set_blocking($this->inotify, 0);
     }
     Timer::add(function ($event) {
         Daemon::$process->fileWatcher->watch();
         if (sizeof(Daemon::$process->fileWatcher->files) > 0) {
             $event->timeout();
         }
     }, 1000000.0 * 1, 'fileWatcher');
 }
All Usage Examples Of PHPDaemon\Core\Daemon::loadModuleIfAbsent