public static function run($id): bool
    {
        $id = abs((int)$id);
        /** @var ServiceEntity $service_entity */
        $service_entity = ServiceEntityRepository::findOneEntityById($id);

        if (!$service_entity || $service_entity->getRunning()) {
            return false;
        }

        $file = Finder::getInstance()->searchForRealPath($service_entity->getFile() . '.php', Finder::TYPE_SERVICES);

        if (!$file || !\file_exists(DIR_BASE . $file)) {
            return false;
        }

        $service_entity->setRunning(1);
        $service_entity->save();

        // No bckground processes
        if (!function_exists('pcntl_fork')) {
            // Run service file
            require DIR_BASE . $file;
            // Set service is done
            self::setDone($id);

            return true;
        }

        // Run as background process
        $pid = pcntl_fork();
        SQL::getInstance()->connect();

        if ($pid == -1) {
            echo $pid . ": Could not start background service for " . $file . "\n";
            // Could not fork
        } else if ($pid) {
            // We are the parent, doing nothing
        } else {
            echo "Running ". $file . "\n";
            // Run service file
            require DIR_BASE . $file;
            // Set service is done
            self::setDone($id);
            exit("Finished ". $file . "\n");
        }

        return true;
    }
public static function run($id): bool
    {
        $id = abs((int)$id);
        /** @var ServiceEntity $service_entity */
        $service_entity = ServiceEntityRepository::findOneEntityById($id);

        if (!$service_entity || $service_entity->getRunning()) {
            return false;
        }

        $file = Finder::getInstance()->searchForRealPath($service_entity->getFile() . '.php', Finder::TYPE_SERVICES);

        if (!$file || !\file_exists(DIR_BASE . $file)) {
            return false;
        }

        $service_entity->setRunning(1);
        $service_entity->save();

        // No bckground processes
        if (!function_exists('pcntl_fork')) {
            // Run service file
            require DIR_BASE . $file;
            // Set service is done
            self::setDone($id);

            return true;
        }

        // Run as background process
        $pid = pcntl_fork();
        SQL::getInstance()->connect();

        if ($pid == -1) {
            echo $pid . ": Could not start background service for " . $file . "\n";
            // Could not fork
        } else if ($pid) {
            // We are the parent, doing nothing
        } else {
            echo "Running ". $file . "\n";
            // Run service file
            require DIR_BASE . $file;
            // Set service is done
            self::setDone($id);
            exit("Finished ". $file . "\n");
        }

        return true;
    }
public static function run ( $ id ) : bool { $ id = abs ( ( int ) $ id ) ; /** @var ServiceEntity $service_entity */ $ service_entity = ServiceEntityRepository :: findOneEntityById ( $ id ) ; if ( ! $ service_entity || $ service_entity -> getRunning ( ) ) { return false ; } $ file = Finder :: getInstance ( ) -> searchForRealPath ( $ service_entity -> getFile ( ) . '.php' , Finder :: TYPE_SERVICES ) ; if ( ! $ file || ! \ file_exists ( DIR_BASE . $ file ) ) { return false ; } $ service_entity -> setRunning ( 1 ) ; $ service_entity -> save ( ) ; // No bckground processes if ( ! function_exists ( 'pcntl_fork' ) ) { // Run service file require DIR_BASE . $ file ; // Set service is done self :: setDone ( $ id ) ; return true ; } // Run as background process $ pid = pcntl_fork ( ) ; SQL :: getInstance ( ) -> connect ( ) ; if ( $ pid == - 1 ) { echo $ pid . ": Could not start background service for " . $ file . "\n" ; // Could not fork } else if ( $ pid ) { // We are the parent, doing nothing } else { echo "Running " . $ file . "\n" ; // Run service file require DIR_BASE . $ file ; // Set service is done self :: setDone ( $ id ) ; exit ( "Finished " . $ file . "\n" ) ; } return true ; }
Run service once

@param $id

@return bool
Run service once