示例#1
0
 public static function init()
 {
     pts_core::init();
     if (defined('QUICK_START') && QUICK_START) {
         return true;
     }
     if (function_exists('cli_set_process_title') && PHP_OS == 'Linux') {
         cli_set_process_title('Phoronix Test Suite');
     }
     pts_define('PHP_BIN', pts_client::read_env('PHP_BIN'));
     $dir_init = array(PTS_USER_PATH);
     foreach ($dir_init as $dir) {
         pts_file_io::mkdir($dir);
     }
     if (PTS_IS_CLIENT) {
         pts_network::client_startup();
     }
     self::core_storage_init_process();
     if (!is_file(PTS_TEMP_STORAGE)) {
         self::build_temp_cache();
     }
     pts_define('PTS_TEST_INSTALL_DEFAULT_PATH', pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/EnvironmentDirectory', '~/.phoronix-test-suite/installed-tests/')));
     pts_define('PTS_SAVE_RESULTS_PATH', pts_strings::parse_for_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Testing/ResultsDirectory', '~/.phoronix-test-suite/test-results/')));
     self::extended_init_process();
     $openbenchmarking = pts_storage_object::read_from_file(PTS_CORE_STORAGE, 'openbenchmarking');
     $openbenchmarking_account_settings = pts_storage_object::read_from_file(PTS_CORE_STORAGE, 'openbenchmarking_account_settings');
     if ($openbenchmarking != null) {
         // OpenBenchmarking.org Account
         pts_openbenchmarking_client::init_account($openbenchmarking, $openbenchmarking_account_settings);
     }
     return true;
 }
示例#2
0
 public function setProcessName($name)
 {
     if (function_exists('cli_set_process_title')) {
         cli_set_process_title($name);
     }
     return $this;
 }
示例#3
0
 public function setTitle($title)
 {
     $this->title = trim($title);
     if (function_exists('cli_set_process_title')) {
         cli_set_process_title($this->title);
     }
 }
示例#4
0
 /**
  * @param EnvironmentInterface $env
  */
 private function setProcessProperties(EnvironmentInterface $env)
 {
     $props = $env->getEnv('cli');
     if ($props['title'] !== 'php' && function_exists('cli_set_process_title')) {
         cli_set_process_title($props['title']);
     }
 }
示例#5
0
文件: swoole.php 项目: xtjsxtj/esp
 private function my_set_process_name($title)
 {
     if (substr(PHP_VERSION, 0, 3) >= '5.5') {
         cli_set_process_title($title);
     } else {
         swoole_set_process_name($title);
     }
 }
示例#6
0
文件: Child.php 项目: heesey/epserver
 protected function init()
 {
     $this->pid = posix_getpid();
     $this->ppid = posix_getppid();
     cli_set_process_title(sprintf('%s(%s)', $this->getName(), $this->getWorker()));
     static::$currentProcess = $this;
     return $this;
 }
示例#7
0
 private function updateProcTitleIfPossible($workerId, $queues)
 {
     if (!function_exists('cli_set_process_title')) {
         return;
     }
     global $argv;
     cli_set_process_title(sprintf("%s: %s watching %s", join(' ', $argv), $workerId, join(', ', $queues)));
 }
示例#8
0
 private static function changeProcessTitleTo($processTitle)
 {
     if (function_exists('cli_set_process_title')) {
         cli_set_process_title($processTitle);
     } elseif (function_exists('setproctitle')) {
         setproctitle($processTitle);
     }
 }
示例#9
0
 private function updateProcTitleIfPossible($jobId)
 {
     if (!function_exists('cli_set_process_title')) {
         return;
     }
     global $argv;
     cli_set_process_title(sprintf("%s: processing %s", join(' ', $argv), $jobId));
 }
示例#10
0
 /**
  * 设置进程名称
  *
  * @param $title
  */
 protected static function setProcessName($title)
 {
     $title = "php_daemon_{$title}";
     if (function_exists('cli_set_process_title')) {
         cli_set_process_title($title);
     } elseif (extension_loaded('proctitle') && function_exists('setproctitle')) {
         setproctitle($title);
     }
 }
示例#11
0
 public static function init()
 {
     set_time_limit(0);
     pts_define_directories();
     // Define directories
     if (function_exists('cli_set_process_title') && !phodevi::is_macosx()) {
         cli_set_process_title('Phoronix Test Suite');
     }
     if (defined('QUICK_START') && QUICK_START) {
         return true;
     }
     pts_define('PHP_BIN', pts_client::read_env('PHP_BIN'));
     pts_define('PTS_INIT_TIME', time());
     if (!defined('PHP_VERSION_ID')) {
         // PHP_VERSION_ID is only available in PHP 5.2.6 and later
         $php_version = explode('.', PHP_VERSION);
         pts_define('PHP_VERSION_ID', $php_version[0] * 10000 + $php_version[1] * 100 + $php_version[2]);
     }
     $dir_init = array(PTS_USER_PATH);
     foreach ($dir_init as $dir) {
         pts_file_io::mkdir($dir);
     }
     if (PTS_IS_CLIENT) {
         pts_network::client_startup();
     }
     self::core_storage_init_process();
     if (!is_file(PTS_TEMP_STORAGE)) {
         self::build_temp_cache();
     }
     //XXX
     pts_define('PTS_ETC_PATH', is_dir('/etc') ? '/etc/phoronix-test-suite/' : false);
     if (is_dir('/usr/local/share/phoronix-test-suite/')) {
         pts_define('PTS_SHARE_PATH', '/usr/local/share/phoronix-test-suite/');
     } else {
         if (is_dir('/usr/share/')) {
             pts_define('PTS_SHARE_PATH', '/usr/share/phoronix-test-suite/');
             if (is_writable('/usr/share') && !is_dir(PTS_SHARE_PATH)) {
                 mkdir(PTS_SHARE_PATH);
             }
         } else {
             pts_define('PTS_SHARE_PATH', false);
         }
     }
     // XXX: technically the config init_files line shouldn't be needed since it should be dynamically called
     // pts_config::init_files();
     pts_define('PTS_TEST_INSTALL_DEFAULT_PATH', pts_client::parse_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Installation/EnvironmentDirectory', '~/.phoronix-test-suite/installed-tests/')));
     pts_define('PTS_SAVE_RESULTS_PATH', pts_client::parse_home_directory(pts_config::read_user_config('PhoronixTestSuite/Options/Testing/ResultsDirectory', '~/.phoronix-test-suite/test-results/')));
     self::extended_init_process();
     $openbenchmarking = pts_storage_object::read_from_file(PTS_CORE_STORAGE, 'openbenchmarking');
     $openbenchmarking_account_settings = pts_storage_object::read_from_file(PTS_CORE_STORAGE, 'openbenchmarking_account_settings');
     if ($openbenchmarking != null) {
         // OpenBenchmarking.org Account
         pts_openbenchmarking_client::init_account($openbenchmarking, $openbenchmarking_account_settings);
     }
     return true;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $tube = $input->getArgument('tube');
     $resolvedTubeName = \Mosaicoon\QueueManager\QueueManager::resolveChannelName($tube);
     cli_set_process_title('JambonQueueListener-' . $resolvedTubeName);
     $worker = new Worker('127.0.0.1', new JobRunner(), new QMLogger($output));
     $this->printFiglet();
     $output->writeln("<info>In attesa di Job in coda sul canale {$resolvedTubeName}...</info>");
     $worker->execute($tube);
 }
示例#13
0
 /**
  * Forks something into another process and returns a deferred object.
  * @param $callable
  * @param string $processTitle
  * @return Fork
  */
 public function fork($callable, $processTitle = null)
 {
     if (!is_callable($callable)) {
         throw new UnexpectedTypeException($callable, 'callable');
     }
     // allow the system to cleanup before forking
     $this->dispatcher->dispatch(Events::PRE_FORK);
     if (-1 === ($pid = pcntl_fork())) {
         throw new ProcessControlException('Unable to fork a new process');
     }
     if (0 === $pid) {
         if (function_exists('cli_set_process_title') && $processTitle !== null) {
             cli_set_process_title($processTitle);
         }
         // reset the list of child processes
         $this->forks = array();
         // setup the shared memory
         $shm = $this->factory->createSharedMemory(null, $this->signal);
         $message = new ExitMessage();
         // phone home on shutdown
         register_shutdown_function(function () use($shm, $message) {
             $status = null;
             try {
                 $shm->send($message, false);
             } catch (\Exception $e) {
                 // probably an error serializing the result
                 $message->setResult(null);
                 $message->setError(Error::fromException($e));
                 $shm->send($message, false);
                 exit(2);
             }
         });
         // dispatch an event so the system knows it's in a new process
         $this->dispatcher->dispatch(Events::POST_FORK);
         if (!$this->debug) {
             ob_start();
         }
         try {
             $result = call_user_func($callable, $shm);
             $message->setResult($result);
             $status = is_integer($result) ? $result : 0;
         } catch (\Exception $e) {
             $message->setError(Error::fromException($e));
             $status = 1;
         }
         if (!$this->debug) {
             $message->setOutput(ob_get_clean());
         }
         exit($status);
     }
     // connect to shared memory
     $shm = $this->factory->createSharedMemory($pid);
     return $this->forks[$pid] = $this->factory->createFork($pid, $shm, $this->debug);
 }
示例#14
0
 private static function runJob($job) : bool
 {
     if ($job !== null) {
         $class = new $job['class']();
         $function = $job['function'];
         \cli_set_process_title('php cron.php ' . $job['class'] . '->' . $function);
         $args = $job['args'];
         $class->{$function}($args);
     }
     return true;
 }
示例#15
0
 public function onWorkerStart($serv, $worker_id)
 {
     // 判定是否为Task进程
     if ($worker_id >= $serv->setting['worker_num']) {
         //echo "----onTaskStart worker_id: {$worker_id} \n";
         cli_set_process_title("php5  task_id {$worker_id}");
     } else {
         //echo "--onWorkerStart worker_id: {$worker_id} \n";
         cli_set_process_title("php5 worker {$worker_id}");
     }
 }
示例#16
0
 /**
  * Sets the process title.
  *
  * @param string $title
  */
 public function setProcessTitle($title)
 {
     if (function_exists('cli_set_process_title')) {
         cli_set_process_title($title);
         //PHP >= 5.5.
     } else {
         if (function_exists('setproctitle')) {
             setproctitle($title);
             //PECL proctitle
         }
     }
 }
示例#17
0
文件: proc.php 项目: hitzheng/ares
 /**
  * 设置进程名
  * @param [type] $title [description]
  */
 public static function setTitle($title)
 {
     if (function_exists('cli_set_process_title')) {
         // PHP >= 5.5
         cli_set_process_title($title);
     } else {
         if (function_exists('setproctitle')) {
             // PECL proctitle >= 0.1.0
             setproctitle($title);
         }
     }
 }
示例#18
0
 public static function setTitle($title)
 {
     $ret = true;
     if (function_exists('cli_set_process_title') && PHP_OS != 'Darwin') {
         cli_set_process_title($title);
     } elseif (function_exists('setproctitle')) {
         setproctitle($title);
     } else {
         $ret = false;
     }
     return $ret;
 }
示例#19
0
 /**
  * 设置进程的名称
  * @param $name
  */
 static function setProcessName($name)
 {
     if (function_exists('cli_set_process_title')) {
         cli_set_process_title($name);
     } else {
         if (function_exists('swoole_set_process_name')) {
             swoole_set_process_name($name);
         } else {
             trigger_error(__METHOD__ . " failed. require cli_set_process_title or swoole_set_process_name.");
         }
     }
 }
示例#20
0
/**
 * @param $name
 */
function process_rename($name)
{
    // hidden Mac OS error。
    set_error_handler(function () {
    });
    if (function_exists('cli_set_process_title')) {
        cli_set_process_title($name);
    } else {
        if (function_exists('swoole_set_process_name')) {
            swoole_set_process_name($name);
        }
    }
    restore_error_handler();
}
示例#21
0
 /**
  * Creates a child process. Returns child PID in parent process, 0 in child process.
  *
  * @param string|null $processTitle
  * @return int
  * @throws RuntimeException
  */
 public function forkChild(string $processTitle = null) : int
 {
     // Close resources prior to forking
     $this->resourceManager->closeResources();
     // Start queueing child signals prior to forking, so no signal gets lost
     $this->startQueueingChildSignals();
     set_error_handler(function ($code, $message, $file, $line) {
         $error = new ErrorException($message, $code, 1, $file, $line);
         throw new RuntimeException('Failed to fork process', 0, $error);
     });
     $pid = pcntl_fork();
     restore_error_handler();
     if ($pid === 0 && null !== $processTitle) {
         cli_set_process_title($processTitle);
     }
     return $pid;
 }
示例#22
0
 public function __construct()
 {
     $http = new swoole_http_server("0.0.0.0", 9501);
     $http->set(array('worker_num' => 50, 'daemonize' => true, 'max_request' => 10000, 'dispatch_mode' => 16));
     $http->setGlobal(HTTP_GLOBAL_ALL);
     $http->on('Start', function () {
         if (function_exists('cli_set_process_title')) {
             cli_set_process_title('app_server');
         } else {
             if (function_exists('swoole_set_process_name')) {
                 swoole_set_process_name('app_server');
             }
         }
     });
     $http->on('Request', array($this, 'onRequest'));
     $http->start();
 }
示例#23
0
 /**
  * @param  callable $job_runner
  */
 public function runNext(callable $job_runner)
 {
     $this->consumer_q->consume(function (IncomingMessage $message) use($job_runner) {
         $start_time = new DateTime();
         $mark_job_as_failed_if_not_successful = $this->getFailureCallback();
         register_shutdown_function($mark_job_as_failed_if_not_successful, $message, $start_time);
         $content = $message->getContent();
         $name = $content['name'];
         $params = $content['params'];
         $meta = $content['meta'];
         $title = implode(" ", $_SERVER['argv']) . " ({$meta['buffered_job_id']}:{$name})";
         cli_set_process_title($title);
         try {
             call_user_func($job_runner, $name, $params);
             $this->markJobAsSuccessful($message, $start_time);
         } finally {
             $mark_job_as_failed_if_not_successful($message, $start_time);
         }
     });
 }
示例#24
0
 public function __construct(Server $server, $id = false)
 {
     $this->worker_class = $server->getWorkerClass();
     $this->shm = new SHM($server, $id);
     $this->shm->write($id, false);
     $this->id = $id ?: getmypid();
     $this->server = $server;
     $this->configureLogger();
     if (extension_loaded('pcntl')) {
         @cli_set_process_title("RMQ Worker [Master: {$server->pid}]");
     }
     $this->configureSignals();
     if (extension_loaded('pcntl')) {
         pcntl_signal_dispatch();
     }
     $this->config = clone $server->config;
     set_error_handler([$this, "errorHandler"]);
     register_shutdown_function([$this, "check_for_fatal"]);
     $this->start();
 }
 /**
  *
  */
 private function init()
 {
     $workers_required = count($this->workers);
     for ($i = 0; $i < $workers_required; $i++) {
         $pid = pcntl_fork();
         $this->child_pids[] = $pid;
         if ($pid == -1) {
             // Failed to fork
             trigger_error('Failed to spawn worker process');
         } else {
             if ($pid) {
                 // We are the parent
                 $this->parent_thread = true;
             } else {
                 // We are the child
                 $worker_number = $i + 1;
                 cli_set_process_title($this->thread_name . ': Child Process #' . $worker_number);
                 call_user_func($this->workers[$i]);
                 break;
             }
         }
     }
 }
示例#26
0
 /**
  * Sets the proccess title
  *
  * This function call requires php5.5+ or the proctitle extension!
  * Empty title strings won't be set.
  * @param string $title the new process title
  * @param array $replacements an associative array of replacment values
  * @return void
  */
 public static function setProcessTitle($title, array $replacements = array())
 {
     // skip when empty title names or running on MacOS
     if (trim($title) == '' || PHP_OS == 'Darwin') {
         return;
     }
     // 1. replace the values
     $title = preg_replace_callback('/\\%([a-z0-9]+)\\%/i', function ($match) use($replacements) {
         if (isset($replacements[$match[1]])) {
             return $replacements[$match[1]];
         }
         return $match[0];
     }, $title);
     // 2. remove forbidden chars
     $title = preg_replace('/[^a-z0-9-_.: \\\\\\]\\[]/i', '', $title);
     // 3. set the title
     if (function_exists('cli_set_process_title')) {
         cli_set_process_title($title);
         // PHP 5.5+ has a builtin function
     } elseif (function_exists('setproctitle')) {
         setproctitle($title);
         // pecl proctitle extension
     }
 }
示例#27
0
 /**
  * Runs the command.
  *
  * The code to execute is either defined directly with the
  * setCode() method or by overriding the execute() method
  * in a sub-class.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return int The command exit code
  *
  * @throws \Exception
  *
  * @see setCode()
  * @see execute()
  *
  * @api
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     // force the creation of the synopsis before the merge with the app definition
     $this->getSynopsis(true);
     $this->getSynopsis(false);
     // add the application arguments and options
     $this->mergeApplicationDefinition();
     // bind the input against the command specific arguments/options
     try {
         $input->bind($this->definition);
     } catch (\Exception $e) {
         if (!$this->ignoreValidationErrors) {
             throw $e;
         }
     }
     $this->initialize($input, $output);
     if (null !== $this->processTitle) {
         if (function_exists('cli_set_process_title')) {
             cli_set_process_title($this->processTitle);
         } elseif (function_exists('setproctitle')) {
             setproctitle($this->processTitle);
         } elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {
             $output->writeln('<comment>Install the proctitle PECL to be able to change the process title.</comment>');
         }
     }
     if ($input->isInteractive()) {
         $this->interact($input, $output);
     }
     $input->validate();
     if ($this->code) {
         $statusCode = call_user_func($this->code, $input, $output);
     } else {
         $statusCode = $this->execute($input, $output);
     }
     return is_numeric($statusCode) ? (int) $statusCode : 0;
 }
示例#28
0
 /**
  * @param \ClassLoader    $autoloader
  * @param \ThreadedLogger $logger
  * @param string          $filePath
  * @param string          $dataPath
  * @param string          $pluginPath
  */
 public function __construct(\ClassLoader $autoloader, \ThreadedLogger $logger, $filePath, $dataPath, $pluginPath)
 {
     self::$instance = $this;
     $this->autoloader = $autoloader;
     $this->logger = $logger;
     $this->filePath = $filePath;
     if (!file_exists($dataPath . "worlds/")) {
         mkdir($dataPath . "worlds/", 0777);
     }
     if (!file_exists($dataPath . "players/")) {
         mkdir($dataPath . "players/", 0777);
     }
     if (!file_exists($dataPath . "CrashDump/")) {
         mkdir($dataPath . "CrashDump/", 0777);
     }
     if (!file_exists($pluginPath)) {
         mkdir($pluginPath, 0777);
     }
     $this->dataPath = realpath($dataPath) . DIRECTORY_SEPARATOR;
     $this->pluginPath = realpath($pluginPath) . DIRECTORY_SEPARATOR;
     $this->console = new CommandReader();
     $version = new VersionString($this->getPocketMineVersion());
     $this->logger->info(TextFormat::GREEN . "  ____            _        _   __  __ _                     " . TextFormat::AQUA . " _____ _ _ _       ");
     $this->logger->info(TextFormat::GREEN . " |  _ \\ ___   ___| | _____| |_|  \\/  (_)_ __   ___          " . TextFormat::AQUA . "| ____| (_) |_ ___ ");
     $this->logger->info(TextFormat::GREEN . " | |_) / _ \\ / __| |/ / _ \\ __| |\\/| | | '_ \\ / _ \\  _____  " . TextFormat::AQUA . "|  _| | | | __/ _ \\ ");
     $this->logger->info(TextFormat::GREEN . " |  __/ (_) | (__|   <  __/ |_| |  | | | | | |  __/ |_____| " . TextFormat::AQUA . "| |___| | | ||  __/");
     $this->logger->info(TextFormat::GREEN . " |_|   \\___/ \\___|_|\\_\\___|\\__|_|  |_|_|_| |_|\\___|         " . TextFormat::AQUA . "|_____|_|_|\\__\\___|");
     $this->logger->info(TextFormat::GREEN . "                               Version: " . TextFormat::AQUA . $version);
     $this->logger->info("Loading pocketmine.yml...");
     if (!file_exists($this->dataPath . "pocketmine.yml")) {
         $content = file_get_contents($this->filePath . "src/pocketmine/resources/pocketmine.yml");
         if ($version->isDev()) {
             $content = str_replace("preferred-channel: stable", "preferred-channel: beta", $content);
         }
         @file_put_contents($this->dataPath . "pocketmine.yml", $content);
     }
     $this->config = new Config($this->dataPath . "pocketmine.yml", Config::YAML, []);
     $this->logger->info("Loading server properties...");
     $this->properties = new Config($this->dataPath . "server.properties", Config::PROPERTIES, ["motd" => "Minecraft: PE Server", "server-port" => 19132, "white-list" => false, "announce-player-achievements" => true, "spawn-protection" => 16, "max-players" => 20, "allow-flight" => false, "spawn-animals" => true, "spawn-mobs" => true, "gamemode" => 0, "force-gamemode" => false, "hardcore" => false, "pvp" => true, "difficulty" => 1, "generator-settings" => "", "level-name" => "world", "level-seed" => "", "level-type" => "DEFAULT", "enable-query" => true, "enable-rcon" => false, "rcon.password" => substr(base64_encode(@Utils::getRandomBytes(20, false)), 3, 10), "auto-save" => true]);
     $this->forceLanguage = $this->getProperty("settings.force-language", false);
     $this->baseLang = new BaseLang($this->getProperty("settings.language", BaseLang::FALLBACK_LANGUAGE));
     $this->logger->info($this->getLanguage()->translateString("language.selected", [$this->getLanguage()->getName(), $this->getLanguage()->getLang()]));
     $this->memoryManager = new MemoryManager($this);
     $this->logger->info($this->getLanguage()->translateString("pocketmine.server.start", [TextFormat::AQUA . $this->getVersion()]));
     if (($poolSize = $this->getProperty("settings.async-workers", "auto")) === "auto") {
         $poolSize = ServerScheduler::$WORKERS;
         $processors = Utils::getCoreCount() - 2;
         if ($processors > 0) {
             $poolSize = max(1, $processors);
         }
     }
     ServerScheduler::$WORKERS = $poolSize;
     if ($this->getProperty("network.batch-threshold", 256) >= 0) {
         Network::$BATCH_THRESHOLD = (int) $this->getProperty("network.batch-threshold", 256);
     } else {
         Network::$BATCH_THRESHOLD = -1;
     }
     $this->networkCompressionLevel = $this->getProperty("network.compression-level", 7);
     $this->networkCompressionAsync = $this->getProperty("network.async-compression", true);
     $this->autoTickRate = (bool) $this->getProperty("level-settings.auto-tick-rate", true);
     $this->autoTickRateLimit = (int) $this->getProperty("level-settings.auto-tick-rate-limit", 20);
     $this->alwaysTickPlayers = (int) $this->getProperty("level-settings.always-tick-players", false);
     $this->baseTickRate = (int) $this->getProperty("level-settings.base-tick-rate", 1);
     $this->scheduler = new ServerScheduler();
     if ($this->getConfigBoolean("enable-rcon", false) === true) {
         $this->rcon = new RCON($this, $this->getConfigString("rcon.password", ""), $this->getConfigInt("rcon.port", $this->getPort()), ($ip = $this->getIp()) != "" ? $ip : "0.0.0.0", $this->getConfigInt("rcon.threads", 1), $this->getConfigInt("rcon.clients-per-thread", 50));
     }
     $this->entityMetadata = new EntityMetadataStore();
     $this->playerMetadata = new PlayerMetadataStore();
     $this->levelMetadata = new LevelMetadataStore();
     $this->operators = new Config($this->dataPath . "ops.txt", Config::ENUM);
     $this->whitelist = new Config($this->dataPath . "white-list.txt", Config::ENUM);
     if (file_exists($this->dataPath . "banned.txt") and !file_exists($this->dataPath . "banned-players.txt")) {
         @rename($this->dataPath . "banned.txt", $this->dataPath . "banned-players.txt");
     }
     @touch($this->dataPath . "banned-players.txt");
     $this->banByName = new BanList($this->dataPath . "banned-players.txt");
     $this->banByName->load();
     @touch($this->dataPath . "banned-ips.txt");
     $this->banByIP = new BanList($this->dataPath . "banned-ips.txt");
     $this->banByIP->load();
     $this->maxPlayers = $this->getConfigInt("max-players", 20);
     $this->setAutoSave($this->getConfigBoolean("auto-save", true));
     if ($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3) {
         $this->setConfigInt("difficulty", 3);
     }
     define("pocketmine\\DEBUG", (int) $this->getProperty("debug.level", 1));
     if ($this->logger instanceof MainLogger) {
         $this->logger->setLogDebug(\pocketmine\DEBUG > 1);
     }
     if (\pocketmine\DEBUG >= 0) {
         @cli_set_process_title($this->getName() . " " . $this->getPocketMineVersion());
     }
     $this->logger->info($this->getLanguage()->translateString("pocketmine.server.networkStart", [$this->getIp() === "" ? "*" : $this->getIp(), $this->getPort()]));
     define("BOOTUP_RANDOM", @Utils::getRandomBytes(16));
     $this->serverID = Utils::getMachineUniqueId($this->getIp() . $this->getPort());
     $this->getLogger()->debug("Server unique id: " . $this->getServerUniqueId());
     $this->getLogger()->debug("Machine unique id: " . Utils::getMachineUniqueId());
     $this->network = new Network($this);
     $this->network->setName($this->getMotd());
     $this->logger->info($this->getLanguage()->translateString("pocketmine.server.info", [$this->getName(), ($version->isDev() ? TextFormat::YELLOW : "") . $version->get(true) . TextFormat::WHITE, $this->getCodename(), $this->getApiVersion()]));
     $this->logger->info($this->getLanguage()->translateString("pocketmine.server.license", [$this->getName()]));
     Timings::init();
     $this->consoleSender = new ConsoleCommandSender();
     $this->commandMap = new SimpleCommandMap($this);
     $this->registerEntities();
     $this->registerTiles();
     InventoryType::init();
     Block::init();
     Item::init();
     Biome::init();
     Effect::init();
     Enchantment::init();
     Attribute::init();
     /** TODO: @deprecated */
     TextWrapper::init();
     $this->craftingManager = new CraftingManager();
     $this->pluginManager = new PluginManager($this, $this->commandMap);
     $this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender);
     $this->pluginManager->setUseTimings($this->getProperty("settings.enable-profiling", false));
     $this->profilingTickRate = (double) $this->getProperty("settings.profile-report-trigger", 20);
     $this->pluginManager->registerInterface(PharPluginLoader::class);
     $this->pluginManager->registerInterface(ScriptPluginLoader::class);
     set_exception_handler([$this, "exceptionHandler"]);
     register_shutdown_function([$this, "crashDump"]);
     $this->queryRegenerateTask = new QueryRegenerateEvent($this, 5);
     $this->network->registerInterface(new RakLibInterface($this));
     $this->pluginManager->loadPlugins($this->pluginPath);
     $this->updater = new AutoUpdater($this, $this->getProperty("auto-updater.host", "www.pocketmine.net"));
     $this->enablePlugins(PluginLoadOrder::STARTUP);
     LevelProviderManager::addProvider($this, Anvil::class);
     LevelProviderManager::addProvider($this, McRegion::class);
     if (extension_loaded("leveldb")) {
         $this->logger->debug($this->getLanguage()->translateString("pocketmine.debug.enable"));
         LevelProviderManager::addProvider($this, LevelDB::class);
     }
     Generator::addGenerator(Flat::class, "flat");
     Generator::addGenerator(Normal::class, "normal");
     Generator::addGenerator(Normal::class, "default");
     Generator::addGenerator(Nether::class, "hell");
     Generator::addGenerator(Nether::class, "nether");
     foreach ((array) $this->getProperty("worlds", []) as $name => $worldSetting) {
         if ($this->loadLevel($name) === false) {
             $seed = $this->getProperty("worlds.{$name}.seed", time());
             $options = explode(":", $this->getProperty("worlds.{$name}.generator", Generator::getGenerator("default")));
             $generator = Generator::getGenerator(array_shift($options));
             if (count($options) > 0) {
                 $options = ["preset" => implode(":", $options)];
             } else {
                 $options = [];
             }
             $this->generateLevel($name, $seed, $generator, $options);
         }
     }
     if ($this->getDefaultLevel() === null) {
         $default = $this->getConfigString("level-name", "world");
         if (trim($default) == "") {
             $this->getLogger()->warning("level-name cannot be null, using default");
             $default = "world";
             $this->setConfigString("level-name", "world");
         }
         if ($this->loadLevel($default) === false) {
             $seed = $this->getConfigInt("level-seed", time());
             $this->generateLevel($default, $seed === 0 ? time() : $seed);
         }
         $this->setDefaultLevel($this->getLevelByName($default));
     }
     $this->properties->save(true);
     if (!$this->getDefaultLevel() instanceof Level) {
         $this->getLogger()->emergency($this->getLanguage()->translateString("pocketmine.level.defaultError"));
         $this->forceShutdown();
         return;
     }
     if ($this->getProperty("ticks-per.autosave", 6000) > 0) {
         $this->autoSaveTicks = (int) $this->getProperty("ticks-per.autosave", 6000);
     }
     $this->enablePlugins(PluginLoadOrder::POSTWORLD);
     $this->start();
 }
示例#29
0
 /**
  * 设置进程名称,需要proctitle支持 或者php>=5.5
  * @param string $title
  * @return void
  */
 protected static function setProcTitle($title)
 {
     // >=php 5.5
     if (function_exists('cli_set_process_title')) {
         @cli_set_process_title($title);
     } elseif (extension_loaded('proctitle') && function_exists('setproctitle')) {
         @setproctitle($title);
     }
 }
示例#30
0
 public function setTitle($flag = 'proxy')
 {
     $title = cli_get_process_title();
     $titles = explode(' --sw', $title, 2);
     $title = sprintf('%s --sw-%s', $titles[0], $flag);
     cli_set_process_title($title);
 }