本文整理汇总了PHP中setproctitle函数的典型用法代码示例。如果您正苦于以下问题:PHP setproctitle函数的具体用法?PHP setproctitle怎么用?PHP setproctitle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setproctitle函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: launchJob
protected function launchJob($jobID)
{
if (FALSE === $this->fire('onLauncher', array(&$this))) {
usleep(20000);
return false;
}
$pid = pcntl_fork();
if ($pid == -1) {
$this->fire('onLaunchJobError', array(&$this));
return false;
} else {
if ($pid) {
$this->currentObjects[$pid] = $this->childObject;
$this->currentJobs[$pid] = $jobID;
if (isset($this->signalQueue[$pid])) {
$this->childSignalHandler(SIGCHLD, $pid, $this->signalQueue[$pid]);
unset($this->signalQueue[$pid]);
}
} else {
unset($this->currentObjects);
$exitStatus = 0;
setproctitle($this->childsProcName);
$this->fire('onLaunchJob', array(&$this));
exit($exitStatus);
}
}
return true;
}
示例2: changeProcessTitleTo
private static function changeProcessTitleTo($processTitle)
{
if (function_exists('cli_set_process_title')) {
cli_set_process_title($processTitle);
} elseif (function_exists('setproctitle')) {
setproctitle($processTitle);
}
}
示例3: setProcessName
/**
* 设置进程名称
*
* @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);
}
}
示例4: _init
protected function _init()
{
setproctitle('Daemon: QueueManager');
$this->_initSockets();
$this->_initFactories();
$this->_processingLoop();
$this->_shutdownProcessingLoop();
exit;
}
示例5: _init
protected function _init()
{
setproctitle('Daemon: downloader');
$this->_initSockets();
$this->_getDownloadListFromWorker();
$this->_checkAndFilterDownloads();
$this->_startDownloads();
exit;
}
示例6: _init
protected function _init()
{
$this->_identity = 'worker/' . uniqid();
setproctitle(sprintf('Daemon: %s', $this->_identity));
$this->_initSocket();
$this->_registerAtQueueManager();
register_shutdown_function(array($this, 'shutdown'));
$this->_processingLoop();
}
示例7: wfProfileOut
function wfProfileOut($fn = '')
{
global $hackwhere, $wgDBname;
if (count($hackwhere)) {
array_pop($hackwhere);
}
if (function_exists("setproctitle") && count($hackwhere)) {
setproctitle($hackwhere[count($hackwhere) - 1] . " [{$wgDBname}]");
}
}
示例8: setTitle
/**
* 设置进程名
* @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);
}
}
}
示例9: setProcessTitle
/**
* 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
}
}
}
示例10: setTitle
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;
}
示例11: wfProfileOut
/**
* Stop profiling of a function
* @param $fn string
*/
function wfProfileOut($fn = '')
{
global $hackwhere, $wgDBname, $haveProctitle;
if (!$haveProctitle) {
return;
}
if (count($hackwhere)) {
array_pop($hackwhere);
}
if (count($hackwhere)) {
setproctitle($hackwhere[count($hackwhere) - 1] . " [{$wgDBname}]");
}
}
示例12: _init
protected function _init()
{
$pid = pcntl_fork();
if ($pid !== 0) {
return;
}
$pidFile = $this->_config->get('pid_file');
if (file_exists($pidFile) && '' != exec('ps -p `cat ' . $pidFile . '` --no-heading')) {
trigger_error('Process running with PID ' . file_get_contents($pidFile), E_USER_NOTICE);
exit(0);
}
file_put_contents($pidFile, getmypid());
setproctitle('Daemon: ForkMaster');
$this->_forkChilds();
$this->_monitorChildProcesses();
}
示例13: run
/**
* Run the execution loop.
*
* Forks into a master and a loop process. The loop process will handle the
* evaluation of all instructions, then return its state via a socket upon
* completion.
*
* @param Shell $shell
*/
public function run(Shell $shell)
{
list($up, $down) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
if (!$up) {
throw new \RuntimeException('Unable to create socket pair.');
}
$pid = pcntl_fork();
if ($pid < 0) {
throw new \RuntimeException('Unable to start execution loop.');
} elseif ($pid > 0) {
// This is the main thread. We'll just wait for a while.
// We won't be needing this one.
fclose($up);
// Wait for a return value from the loop process.
$read = array($down);
$write = null;
$except = null;
if (stream_select($read, $write, $except, null) === false) {
throw new \RuntimeException('Error waiting for execution loop.');
}
$content = stream_get_contents($down);
fclose($down);
if ($content) {
$shell->setScopeVariables(@unserialize($content));
}
return;
}
// This is the child process. It's going to do all the work.
if (function_exists('setproctitle')) {
setproctitle('psysh (loop)');
}
// We won't be needing this one.
fclose($down);
// Let's do some processing.
parent::run($shell);
// Send the scope variables back up to the main thread
fwrite($up, $this->serializeReturn($shell->getScopeVariables()));
fclose($up);
exit;
}
示例14: setProcessTitle
/**
* 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
}
}
示例15: renameProcess
/**
* Rename process name
*
* @param string $prefix Prefix for the process name
* @throws NotSupportedException
*/
protected function renameProcess($prefix = '')
{
$name = $this->getProcessName();
if (false === empty($prefix)) {
$name = $prefix . '-' . $name;
}
//rename process
if (version_compare(PHP_VERSION, '5.5.0') >= 0) {
cli_set_process_title($name);
} else {
if (function_exists('setproctitle')) {
setproctitle($name);
} else {
throw new NotSupportedException("Can't find cli_set_process_title or setproctitle function");
}
}
}