START daemon

1) get

@return bool
341652
public function start()
    {

        $state = $this->getState();

        if (in_array($state, [self::STATE_T_START, self::STATE_T_STOP, self::STATE_T_KILL])) {

            $processId = $this->getProcessId();

            if (!$this->processExists()) {

                $this->getLogger()
                    ->warning("Daemon is ill can't find process {$processId}, try clean data and continue starting",
                        [__NAMESPACE__]);
                $this->cleanData();

                // continue start

            } else {
                $this->getLogger()
                    ->info("Daemon can't START, cause state : {$state}, and process exists {$processId}",
                        [__NAMESPACE__]);

                return false;
            }
        }

        $this->setProcessId($pid = intval(getmypid()));
        $this->setData(self::P_CREATED_TIME, time());
        $this->setState(self::STATE_T_START);

        try {
            $this->mainLoop();
            $this->waitManagersDone();
        } catch (\Exception $ex) {
            $this->getLogger()->warning($ex->getMessage(), [__NAMESPACE__]);
        }

        $this->cleanData();

        return true;
    }
1210171
public function start()
    {
        if ($this->started) {
            return;
        }

        $auth = $this->getAuthFlag();

        $command = 'transmission-remote -C ' . $auth
            . ' -' . ($this->encryption ? 'er' : 'ep')
            . ' -p ' . $this->port
            . ' -' . ($this->upnp ? 'm' : 'M')
            . ($this->downloadPath ? ' -w ' . $this->downloadPath : '');
        $this->execute($command);

        $this->execute('transmission-remote ' . $auth . ' -l');
        if ($this->getStatus() == 1) {
            $this->execute('transmission-daemon');
        }

        $this->started = true;
    }
926157
public static function start()
    {
        static $handle = 0;

        $start_time = microtime(true);

        self::$benchmarks[$handle] = $start_time;

        return $handle++;
    }
115125
public function work()
    {

        // Deal with differences in mode
        switch ($this->mode) {

            // Connect to daemon mode
            case 'daemon':
                return $this->parseSockData($this->getSock());
            break;

            // Syslog every n seconds
            case 'syslog':
                return $this->parseSysLogData();
            break;

            // Some other mode
            default:
                throw new Exception('Not supported mode');
            break;
        }
    }
584143
public function start()
    {
        if (!headers_sent()) {
            if (!$this->started && $this->status() !== PHP_SESSION_ACTIVE) {
                session_start();
                $this->started = true;

                return true;
            }
        }

        return false;
    }
992374
def start(self):
        
        # Check for a pidfile to see if the daemon already runs
        pid = None
        if os.path.exists(self.pidfile):
            try:
                pf = file(self.pidfile,'r')
                pid = int(pf.read().strip())
                pf.close()
            except IOError:
                pid = None

        if pid:
            message = "pidfile %s already exist. Daemon already running?\n"
            sys.stderr.write(message % self.pidfile)
            sys.exit(1)

        # 
        self.daemonize()
        self.run()
19392
public function start()
    {
        if (!$this->isActive()) {
            return true;
        }

        if (!$this->hasCache()) {
            ob_start();
            return true;
        }

        $this->getCache(true);
        return false;
    }
943930
protected function waitPid()
    {
        start:
        $pid = \pcntl_waitpid(-1, $status, WNOHANG);
        if ($pid > 0) {
            foreach ($this->collections as $col) {
                foreach ($col->threads as $k => $t) {
                    if ($t->pid === $pid) {
                        $t->setTerminated();
                        unset($col->threads[$k]);
                        goto start;
                    }
                }
            }
        }

        return false;
    }
1158657
public function start(): int
    {
        $scripts = $this->installManager->install();

        $this->processRunner = new ProcessRunner($scripts->getStubService(), $this->getArguments());

        $processId =  $this->processRunner->run();
        \sleep(1); // wait for server to start

        return $processId;
    }
1147057
public function start() {
        // NOTE: memcached before 2.2.0 expires session locks automatically after max_execution_time,
        //       this leads to major difference compared to other session drivers that timeout
        //       and stop the second request execution instead.

        $default = ini_get('max_execution_time');
        set_time_limit($this->acquiretimeout);

        $isnewsession = empty($_COOKIE[session_name()]);
        $starttimer = microtime(true);

        $result = parent::start();

        // If session_start returned TRUE, but it took as long
        // as the timeout value, and the $_SESSION returned is
        // empty when should not have been (isnewsession false)
        // then assume it did timeout and is invalid.
        // Add 1 second to elapsed time to account for inexact
        // timings in php_memcached_session.c.
        // @TODO Remove this check when php-memcached is fixed
        // to return false after key lock acquisition timeout.
        if (!$isnewsession && $result && count($_SESSION) == 0
            && (microtime(true) - $starttimer + 1) >= floatval($this->acquiretimeout)) {
            $result = false;
        }

        set_time_limit($default);
        return $result;
    }
793082
public function start()
    {
        if (!$this->hasStarted()) {
            $this->setStarted();
            $this->dispatch(RunEvent::STARTED, new RunEvent($this));
            try {
                try {
                    $output = call_user_func($this->callback);
                    $this->handleOutput($output);
                    $this->setFinished();
                    $this->successful = true;
                    $this->dispatch(RunEvent::SUCCESSFUL, new RunEvent($this));
                } catch (Exception $e) {
                    $this->setFinished();
                    $this->successful = false;
                    $this->exception = $e;
                    $this->dispatch(RunEvent::FAILED, new RunEvent($this));
                } catch (Throwable $e) {
                    $this->setFinished();
                    $this->successful = false;
                    $this->exception = $e;
                    $this->dispatch(RunEvent::FAILED, new RunEvent($this));
                }
            } finally {
                $this->dispatch(RunEvent::COMPLETED, new RunEvent($this));
            }
        }

        return $this;
    }
1206501
function start()
	{
		$originalProps = $this->props;		
		$response = new ET_Perform($this->authStub, $this->obj, 'start', $this->props);
		if ($response->status) {
			$this->lastTaskID = $response->results[0]->Task->ID;
		}
		$this->props = $originalProps;
		return $response;
	}
350855
public function start()
    {
        if ($this->isStarted()) {
            return true;
        }

        /*
         * Write and Close handlers are called after destructing objects since PHP 5.0.5.
         * Thus destructors can use sessions but session handler can't use objects.
         * So we are moving session closure before destructing objects.
         */
        session_register_shutdown();

        session_cache_limiter('none');

        if (!session_start()) {
            throw new \RuntimeException('Failed to start the session');
        }

        static::$started = true;

        return true;
    }
546454
public function start()
    {
        if (count($this->tasks) == 0)
            throw new \Exception("There are no tasks defined - can not start");

        $this->started = true;

        $options = static::getOptions();
        $debug = @$options['debug'] === true;

        $pidFile = $options['pid_file'];
        if (!$pidFile)
            throw new \Exception("No pid_file in the config");

        $fpPid = fopen($pidFile, "c");
        if (!$fpPid)
            throw new \Exception("Could not open " . $pidFile);

        if (!flock($fpPid, LOCK_EX | LOCK_NB)) {
            fclose($fpPid);
            if ($debug)
                echo "==> Daemon already running" . PHP_EOL;
            return $this;
        }

        if ($debug)
            echo "==> Starting the daemon... " . PHP_EOL;

        $fork = pcntl_fork();
        if ($fork < 0)
            throw new \Exception("fork() failed: $fork");
        else if ($fork)
            return $this;

        ftruncate($fpPid, 0);
        fwrite($fpPid, getmypid() . PHP_EOL);
        fflush($fpPid);
        chmod($pidFile, 0666);

        declare(ticks = 1);

        $exitCallback = function ($signo) use ($fpPid, $pidFile, $debug) {
            if ($debug)
                echo "==> Cleaning and exiting" . PHP_EOL;

            foreach ($this->pids as $pid) {
                if ($debug)
                    echo "==> Terminating worker PID $pid" . PHP_EOL;
                posix_kill($pid, SIGTERM);
            }
            foreach ($this->pids as $pid)
                pcntl_waitpid($pid, $status);

            flock($fpPid, LOCK_UN);
            fclose($fpPid);
            @unlink($pidFile);

            if ($debug)
                echo "==> Daemon is shut down" . PHP_EOL;
            exit;
        };

        pcntl_signal(SIGTERM, $exitCallback);
        pcntl_signal(SIGINT, $exitCallback);
        pcntl_signal_dispatch();

        $sid = posix_setsid();
        if ($sid < 0)
            throw new \Exception("setsid() failed: $sid");

        $gmWorker = new GearmanWorker();
        $gmWorker->addServer($options['gearman']['host'], $options['gearman']['port']);

        foreach ($this->tasks as $name => $object) {
            $function = $options['namespace'] . '-' . $name;
            $task = function ($job) use ($name, $function, $object, $options) {
                if (@$options['debug'] === true)
                    echo "==> Running worker for: $function (PID " . getmypid() . ")" . PHP_EOL;

                $worker = clone $object;
                $data = json_decode($job->workload(), true);
                $worker->setData($data);

                if (@$options['debug'] !== true)
                    ob_start();
                $worker->run($this->exitRequested);
                if (@$options['debug'] !== true)
                    ob_end_clean();
            };
            $gmWorker->addFunction($function, $task);
        }

        while (true) {
            $dead = pcntl_waitpid(-1, $status, WNOHANG);
            while ($dead > 0) {
                if (@$options['debug'] === true)
                    echo "==> Worker PID $dead terminated" . PHP_EOL;

                $index = array_search($dead, $this->pids);
                if ($index !== false)
                    unset($this->pids[$index]); 

                $dead = pcntl_waitpid(-1, $status, WNOHANG);
            }

            while (count($this->pids) < $options['num_workers']) {
                $pid = pcntl_fork();
                if ($pid == 0) {
                    declare(ticks = 1);

                    $exitCallback = function ($signo) {
                        $this->exitRequested = true;
                    };

                    pcntl_signal(SIGTERM, $exitCallback);
                    pcntl_signal(SIGINT, $exitCallback);
                    pcntl_signal_dispatch();

                    $this->pids = [];
                    $gmWorker->setTimeout(1000);
                    while (!$this->exitRequested) {
                        $gmWorker->work();
                        $code = $gmWorker->returnCode();
                        switch ($code) {
                            case GEARMAN_TIMEOUT:
                                sleep(1);
                                break;
                            case GEARMAN_SUCCESS:
                                $this->exitRequested = true;
                                break;
                            default:
                                if (@$options['debug'] === true)
                                    echo "==> Worker failed: $code";
                                exit(1);
                        }
                    }
                    exit;
                } else if ($pid > 0) {
                    $this->pids[] = $pid;
                }
            }

            sleep(1);
        }
    }
955291
public function sessionStart()
    {
        if ( $this->storage && !$this->storage->isStarted() )
        {
            $this->storage->start();
        }

        return true;
    }
1295834
public function start() {
		ConnectionManager::getDataSource($this->_TaskServer->useDbConfig)->reconnect(array('persistent' => false));
		$this->_Shell->out("Task #{$this->_task['id']} started");
		$this->_task['started'] = $this->_getCurrentDateTime();
		$this->_task['stderr'] = '';
		$this->_task['stdout'] = '';
		$this->_TaskServer->started($this->_task);
		$this->_run();
		return $this->_task;
	}
1352646
public function start()
    {
        if (!$this->open()) {
            return false;
        }

        foreach ($this->_servers as $s) {
            // Servername, port, sharedsecret, timeout, retries
            if (!$this->putServer($s[0], $s[1], $s[2], $s[3], $s[4])) {
                return false;
            }
        }

        if (!empty($this->_configfile)) {
            if (!$this->putConfigfile($this->_configfile)) {
                return false;
            }
        }

        $this->createRequest();
        $this->putStandardAttributes();
        $this->putAuthAttributes();
        return true;
    }