Generates a new snowflake.
@param int  $workerID   Valid values are in the range of 0-31.
@param int  $processID  Valid values are in the range of 0-31.
@return string
763728
static function generate(int $workerID = 1, int $processID = 0) {
        if($workerID > 31 || $workerID < 0) {
            throw new \InvalidArgumentException('Worker ID is out of range');
        }
        
        if($processID > 31 || $processID < 0) {
            throw new \InvalidArgumentException('Process ID is out of range');
        }
        
        $time = \microtime(true);
        
        if($time === static::$incrementTime) {
            static::$incrementIndex++;
            
            if(static::$incrementIndex >= 4095) {
                \usleep(1000);
                
                $time = \microtime(true);
                static::$incrementIndex = 0;
            }
        } else {
            static::$incrementIndex = 0;
            static::$incrementTime = $time;
        }
        
        $workerID = \str_pad(\decbin($workerID), 5, 0, \STR_PAD_LEFT);
        $processID = \str_pad(\decbin($processID), 5, 0, \STR_PAD_LEFT);
        
        $mtime = \explode('.', ((string) $time));
        if(\count($mtime) < 2) {
            $mtime[1] = '000';
        }
        
        $time = ((string) (((int) $mtime[0]) - static::EPOCH)).\substr($mtime[1], 0, 3);
        
        if(\PHP_INT_SIZE === 4) {
            $binary = \str_pad(\base_convert($time, 10, 2), 42, 0, \STR_PAD_LEFT).$workerID.$processID.\str_pad(\decbin(static::$incrementIndex), 12, 0, \STR_PAD_LEFT);
            return \base_convert($binary, 2, 10);
        } else {
            $binary = \str_pad(\decbin(((int) $time)), 42, 0, \STR_PAD_LEFT).$workerID.$processID.\str_pad(\decbin(static::$incrementIndex), 12, 0, \STR_PAD_LEFT);
            return ((string) \bindec($binary));
        }
    }
1127961
public function nextId()
    {
        $timestamp = floor(microtime(true) * 1000) - $this->epochTimeStamp;
        if($timestamp > $this->maxTimeStamp) {
            throw new Exception('Snowflake: TimeStamp overflow. Unable to generate any more IDs');
        }
        
        $machine = $this->machineId;
        if($machine < 0 || $machine > 1023) {
            throw new Exception('Snowflake: Machine ID out of range');
        }
        $sequence = mt_rand(0, 4095);
        if(PHP_INT_SIZE == 4) {
            return $this->makeId32($timestamp, $machine, $sequence);
        } else {
            return $this->makeId64($timestamp, $machine, $sequence);
        }
    }
785107
public function writeProgress($taskId, Progress $progress)
    {
        return $this->write($taskId, [
            'progress_percent'      => $progress->percent,
            'progress_step'         => $progress->step,
            'progress_name'         => $progress->stepName,
            'progress_steps'        => $progress->totalSteps,
            'progress_remaining'    => $progress->leftOverSeconds
        ]);
    }
89966
public function onWorkerStart($server, $workid) {

        try {

            //init yii2 application
            $this->yiiConfig = require_once($this->yiiConfigFile);

            //register service
            $dir = ROOT_DIR . $this->config['service']['path'];
            $namespace = $this->config['service']['namespace'];

            $yiiConfig = $this->yiiConfig;
            $dbConfig = require DB_CONFIG_FILE;
            $this->__set('onBeforeInvoke',function() use ($yiiConfig,$dbConfig) {
                $application = new Application($yiiConfig);
                $application->run();
            });
            $this->__set('onAfterInvoke',function() use ($dbConfig) {
                \Yii::$app->release($dbConfig);
                \Yii::$app = null;
            });

            $this->registerService($dir, $namespace, $server);
            $asyncDir = $dir . 'async' . DIRECTORY_SEPARATOR;
            $this->registerService($asyncDir, $namespace, $server, '_async');

            $worker_num = $this->config['setting']['worker_num'];

            if (!function_exists('cli_set_process_title')) {
                if ($workid >= $worker_num) {
                    swoole_set_process_name($this->config['server']['base.process.name'] . 'Task');
                } else {
                    swoole_set_process_name($this->config['server']['base.process.name'] . 'Worker');
                }
            } else {
                if ($workid >= $worker_num) {
                    cli_set_process_title($this->config['server']['base.process.name'] . 'Task');
                } else {
                    cli_set_process_title($this->config['server']['base.process.name'] . 'Worker');
                }
            }
        } catch(\Exception $ex) {
            $this->access_log('server exit.Exception = ' . $ex->getMessage());
        }
    }
133387
protected function unregisterJob(string $jobName, string $workerId) : bool
    {
        if (!isset($this->workerJobCapabilities[$jobName])) {
            return true;
        }
        if (($key = array_search($workerId, $this->workerJobCapabilities[$jobName])) !== false) {
            unset($this->workerJobCapabilities[$jobName][$key]);
        }
        if (empty($this->workerJobCapabilities[$jobName])) {
            unset($this->workerJobCapabilities[$jobName]);
        }
        return true;
    }
1029719
public function dispatchWorkerStart(int $workerId)
    {
        $this->settings["workerId"] = $workerId;

        $loadProcessor = new LoadProcessor($this->container);
        $loadProcessor->load($this->settings);

        $this->collectMiddleware();

        foreach ($this->workerMiddleware as $middleware) {
            $middleware->__invoke($this->settings);
        }
    }
1048877
public function scheme(string $productId): string
    {
        $params = [
            'appid' => $this['config']->app_id,
            'mch_id' => $this['config']->mch_id,
            'time_stamp' => time(),
            'nonce_str' => uniqid(),
            'product_id' => $productId,
        ];

        $params['sign'] = Support\generate_sign($params, $this['config']->key);

        return 'weixin://wxpay/bizpayurl?'.http_build_query($params);
    }
442380
public function onWorkerStart(Server $server, int $workerId)
    {
        // Init Worker and TaskWorker
        $setting = $server->setting;
        $isWorker = false;

        if ($workerId >= $setting['worker_num']) {
            // TaskWorker
            ApplicationContext::setContext(ApplicationContext::TASK);
            ProcessHelper::setProcessTitle($this->serverSetting['pname'] . ' task process');
        } else {
            // Worker
            $isWorker = true;
            ApplicationContext::setContext(ApplicationContext::WORKER);
            ProcessHelper::setProcessTitle($this->serverSetting['pname'] . ' worker process');
        }

        $this->beforeWorkerStart($server, $workerId, $isWorker);

        $this->fireServerEvent(SwooleEvent::ON_WORKER_START, [$server, $workerId, $isWorker]);
    }
2254
public function logProcessFailed(ProcessId $processId, \DateTimeImmutable $finishedAt)
    {
        $data = [
            'finished_at' => $finishedAt->format(\DateTime::ISO8601),
            'status' => self::STATUS_FAILED,
        ];

        $entry = $this->loadProcessEntryIfExists($processId);

        if (is_null($entry)) {
            $this->insertNewEntry($processId, $data);
        } else {
            $this->updateEntry($processId, $data);
        }
    }
944675
public function logProcessSucceed(ProcessId $processId, \DateTimeImmutable $finishedAt)
    {
        $data = [
            'finished_at' => $finishedAt->format(\DateTime::ISO8601),
            'status' => self::STATUS_SUCCEED,
        ];

        $entry = $this->loadProcessEntryIfExists($processId);

        if (is_null($entry)) {
            $this->insertNewEntry($processId, $data);
        } else {
            $this->updateEntry($processId, $data);
        }
    }
511912
public function onWorkerError(SwServer $server, int $workerId, int $workerPid, int $exitCode)
    {
        $workerType = $server->taskworker ? 'task' : 'worker';

        // {{ log
        $this->get('logger')->info('Worker 进程异常退出', [
            'id' => $workerId,
            'pid' => $workerPid,
            'type' => ucfirst($workerType),
            'exitcode' => $exitCode,
        ]);
        // }}

        unset($workerType);

        $this->callProtocolMethod('onError', $server, $workerId);
    }
312798
public function generatePerimeter($siteId)
    {
        $treeFolders = $this->folderRepository->findFolderTree($siteId);

        return $this->generateTreePerimeter($treeFolders);
    }
272961
public static function nPost(string $name, $data, $workerID = -1)
    {
        $task = TaskParser::getInstance()->getTask($name);
        $paramClass = $task['Task']->paramClass;
        return static::post(new TaskInfo(new $task['className'], new $paramClass($data)), $workerID);
    }
1018531
public function onWorkerStart(\Swoole\Server $server, int $worker_id)
    {
        // STDOUT_LOG模式，不打印 worker stop 输出
        if ( getenv('STDOUT_LOG') ) {
            echo date('Y-m-d H:i:s') . " |\033[31m ...... http worker process start[id={$worker_id} pid={$server->worker_pid}] ......\033[0m \n";
        }

        // Add event Listener
        $this->add_event_listener('onWorkerStart');
    }
602120
public static function task($data, $worker_id = -1, $callback = null) {
		if ($callback === true) {
			return self::$server->taskCo([$data]);
		} elseif (is_callable($callback)) {
			self::$server->task($data, $worker_id, $callback);
		} else {
			self::$server->task($data, $worker_id);
		}
	}
1124120
function processIDText()
    {
        if ( is_numeric( $this->ProcessID ) and $this->ProcessID > 0 )
        {
            return $this->ProcessID;
        }

        return ezpI18n::tr( 'ezscriptmonitor', 'n/a' );
    }
450761
protected function getIncrementalProcessOutput(Process $process): string
    {
        // Get the last stdout output from the process.
        $incrementalOutput = $process->getIncrementalOutput();

        // Get the last error output from the process.
        $incrementalErrorOutput = $process->getIncrementalErrorOutput();

        if ($incrementalErrorOutput != '') {
            $incrementalOutput = $incrementalErrorOutput;
        }

        // Make sure the output does not contain unwanted ansi escape sequences.
        return $this->sanitizeOutput($incrementalOutput);
    }