protected function run()
    {
        Daemon::$process = $this;

        $this->prepareSystemEnv();
        class_exists('Timer'); // ensure loading this class
        gc_enable();

        $this->callbacks = new StackCallbacks;

        /*
         * @todo This line must be commented according to current libevent binding implementation.
         * May be uncommented in future.
         */
        //EventLoop::init()

        if (EventLoop::$instance) {
            $this->registerEventSignals();
        } else {
            $this->registerSignals();
        }

        $this->workers = new Collection();
        $this->collections['workers'] = $this->workers;
        $this->ipcthreads = new Collection;
        $this->collections['ipcthreads'] = $this->ipcthreads;

        Daemon::$appResolver->preload(true);

        $this->spawnIPCThread();
        $this->spawnWorkers(
            min(
                Daemon::$config->startworkers->value,
                Daemon::$config->maxworkers->value
            )
        );
        $this->timerCb = function ($event) use (&$cbs) {
            static $c = 0;

            ++$c;

            if ($c > 0xFFFFF) {
                $c = 1;
            }

            if (($c % 10 == 0)) {
                gc_collect_cycles();
            }

            if (!$this->lastMpmActionTs || ((microtime(true) - $this->lastMpmActionTs) > $this->minMpmActionInterval)) {
                $this->callMPM();
            }
            if ($event) {
                $event->timeout();
            }
        };

        if (EventLoop::$instance) { // we are using libevent in Master
            Timer::add($this->timerCb, 1e6 * Daemon::$config->mpmdelay->value, 'MPM');
            EventLoop::$instance->run();
        } else { // we are NOT using libevent in Master
            $lastTimerCall = microtime(true);
            $func = $this->timerCb;
            while (!$this->breakMainLoop) {
                $this->callbacks->executeAll($this);
                if (microtime(true) > $lastTimerCall + Daemon::$config->mpmdelay->value) {
                    $func(null);
                    $lastTimerCall = microtime(true);
                }
                $this->sigwait();
            }
        }
    }