本文整理汇总了PHP中Process::getPid方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::getPid方法的具体用法?PHP Process::getPid怎么用?PHP Process::getPid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Process
的用法示例。
在下文中一共展示了Process::getPid方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reload
/**
* start the same number processes and kill the old sub process
* just like nginx -s reload
* this method will block until all the old process exit;
*
* @param bool $block
*/
public function reload($block = true)
{
$old_process = $this->processes;
for ($i = 0; $i < $this->max; $i++) {
$process = new Process($this->runnable);
$process->start();
$this->processes[$process->getPid()] = $process;
}
foreach ($old_process as $process) {
$process->shutdown();
$process->wait($block);
unset($this->processes[$process->getPid()]);
}
}
示例2: ensureRunning
public static function ensureRunning($cmd, $pidfile, $restart = false)
{
$pidfile = '/var/run/' . $pidfile;
// get pid from pidfile, protecting against invalid data
$p1 = null;
if (file_exists($pidfile) && is_readable($pidfile)) {
$pid = substr(file_get_contents($pidfile), 0, 64);
$p1 = new Process();
$p1->setPid($pid);
}
if ($restart && $p1) {
$p1->stop();
}
// check whether process with this pid is running
if (!$p1 || !$p1->status()) {
// check that we can write the pidfile, to avoid spawning endless processes
if (file_put_contents($pidfile, 'test')) {
$p2 = new Process($cmd);
file_put_contents($pidfile, $p2->getPid());
}
return true;
}
return false;
}
示例3: checkPidFile
function checkPidFile($pidfile = null)
{
if ($pidfile == null) {
if ($this->_pidfile) {
$pidfile = $this->_pidfile;
} else {
$pidfile = $this->getName() . '.pid';
}
}
logger::debug('Checking pidfile: %s', $pidfile);
// Check if the process exist
if (file_exists($pidfile)) {
$pid = file_get_contents($pidfile);
$p = new Process($pid);
logger::debug(' - Inspecting pid %d', $pid);
if ($p->exists()) {
// Already running
return self::PROCESS_RUNNING;
}
unlink($pidfile);
$retval = self::PROCESS_STALE;
} else {
$retval = self::PROCESS_CLEAR;
}
$tp = new Process();
file_put_contents($pidfile, $tp->getPid());
$this->_pidfile = $pidfile;
return $retval;
}
示例4: crawler_exec
private function crawler_exec($keywords, $initial_date, $final_date)
{
$crawler_dir = Configure::read('Crawler.path');
$scrapy_path = Configure::read('Crawler.scrapy.path');
$crawler_name = "folha-spider";
$command = "cd {$crawler_dir} ; {$scrapy_path} crawl {$crawler_name} " . " -a keywords={$keywords} " . " -a initial_date={$initial_date} " . " -a final_date={$final_date}";
$this->log("Runing crawler with command {$command}", 'debug');
$process = new Process($command);
return $process->getPid();
}
示例5: spawn
/**
* fork process with job
*
* @return
*/
public function spawn()
{
$worker = $this->ready();
$ident = $this->getIdent($worker);
//use Process
$p = new Process($worker);
$p->start();
$pid = $p->getPid();
if ($pid) {
$this->childPool[$ident][$pid] = $pid;
}
// //@TODO
// $pid = pcntl_fork();
// if ($pid == -1) {
// } elseif ($pid) {
// $this->childPool[$ident][$pid] = $pid;
// } else {
// //@TODO
// //$this->setOwner($name = 'www');
// //$this->setTitle($title);
// $this->childPool[$ident] = [];
// //$cid = getmypid();
// //echo "\ngetmypid={$cid}\n";
// // 这个符号表示恢复系统对信号的默认处理
// pcntl_signal(SIGTERM, SIG_DFL);
// pcntl_signal(SIGCHLD, SIG_DFL);
// call_user_func_array($worker, array());
// //call_user_func_array($worker);
// exit(0);
// }
}
示例6: delete
/**
* @param Process $process
* @return void
*/
public function delete(Process $process)
{
unset($this->processes[$process->getPid()]);
}
示例7: start
/**
* start the pool
*/
public function start()
{
$alive_count = $this->aliveCount();
// create sub process and run
if ($alive_count < $this->max) {
$need = $this->max - $alive_count;
for ($i = 0; $i < $need; $i++) {
$process = new Process($this->runnable);
$process->start();
$this->processes[$process->getPid()] = $process;
}
}
}
示例8: start_worker
private function start_worker($function, $schema_id)
{
$cmd = "php cli.php worker {$schema_id} {$function} > protected/log/gearman_worker.{$schema_id}.{$function}.log 2>&1";
$p = new Process($cmd);
return $p->getPid();
}
示例9: setCurrentProcess
/**
* Set the current process.
*
* @param Process $proc the process to set as current, the attribute <b>pid</b> should be filled with the process pid.
* @throws EyeInvalidArgumentException If the arguments are incorrect
* @throws EyeProcException If there is no such process with the given pid
*/
public function setCurrentProcess(Process $proc = null)
{
if ($proc !== null) {
$processTable = $this->getProcessesTable();
$pid = $proc->getPid();
if (!isset($processTable[$pid])) {
throw new EyeProcException('Process $proc with PID ' . $pid . ' not found.');
}
}
$this->currentProcess = $proc;
}
示例10: stop
function stop()
{
//stop function
global $conf;
global $db;
$result = $db->query("SELECT count(*) AS C FROM pid");
$row = $result->fetchArray();
// output data of each row
$result = $db->query("SELECT * FROM pid LIMIT 1");
$row = $result->fetchArray();
$process = new Process();
$process->setPid($row["pid"]);
if (!$process->status()) {
$sql = "DELETE FROM pid";
$result = $db->query($sql);
$return_array["info"] = "process already dead";
} else {
$response_array["pid"] = $process->getPid();
$process->stop();
$sql = "DELETE FROM pid";
$result = $db->query($sql);
$return_array["info"] = "process stopped";
}
sleep(1);
cleanpl();
$return_array["status"] = 0;
return $return_array;
}