/**
  * {@inheritdoc}
  *
  * The type of worker created depends on the extensions available. If multi-threading is enabled, a WorkerThread
  * will be created. If threads are not available, a WorkerFork will be created if forking is available, otherwise
  * a WorkerProcess will be created.
  */
 public function create() : Worker
 {
     if (Thread::enabled()) {
         return new WorkerThread();
     }
     if (Fork::enabled()) {
         return new WorkerFork();
     }
     return new WorkerProcess();
 }
 public function actionGetList($limit = 1000, $win_min = null, $live = false)
 {
     $forks = Fork::model()->with(['event', 'f1_event', 'f2_event', 'f3_event'])->findAll(['condition' => implode(' and ', array_filter(['win is not null', 'event.visible = true', $win_min !== null ? 'win > ' . $win_min : null, $live ? '(event.islive = true)' : null])), 'order' => 'win desc', 'limit' => $limit]);
     $list = [];
     foreach ($forks as $fork) {
         $item = $fork->attributes;
         $item['event'] = $fork->event;
         $item['events'] = $fork->eventsByField;
         $list[] = $item;
     }
     $this->renderJson(['list' => $list, 'events_updated' => Yii::app()->settings->get('events_updated')]);
 }
示例#3
0
 private function processJob()
 {
     while (count($this->forkMap) < $this->size && !empty($this->jobQueue)) {
         $jobId = array_pop($this->jobQueue);
         $data = $this->jobMap[$jobId];
         $this->jobForkMap[$jobId] = $fork = new Fork($this->runnable);
         $fork->start();
         $this->logger->trace("save fork in forkMap[{$fork->getPid()}]");
         $this->forkMap[$fork->getPid()] = $fork;
         $fork->send($data);
     }
 }
示例#4
0
    die("no directory with testcases given\n");
}
$strTestDir = $argv[1];
if (!is_dir($strTestDir)) {
    die("given path is not a directory: {$strTestDir}\n");
}
#########################
# initialize ipc-queues #
#########################
# initialize ipc-queue empty, to avoid messages from old test-cases
$objQueue = new \SimpleIPC(QUEUE_IDENTIFIER);
$objQueue->clear();
#################################
# initialize forking-management #
#################################
$objFork = new \Fork();
$objFork->setMaxForks(MAX_FORKS);
####################################
# initialize runtime-configuration #
####################################
# get id of the process - it will be the parent of all forked childs
$intParentPID = posix_getppid();
# get a list of all user-definied functions until here
# we can skip them when looking for newly definied test-cases
$arrAllFunctions = get_defined_functions();
$arrDefinedFunctions = $arrAllFunctions['user'];
############################################
# find all test-files and their test-cases #
############################################
$arrTestCases = array();
# closure to read test-cases from the queue
示例#5
0
文件: fork.php 项目: blogdaren/debug
        echo "  -H             显示帮助信息\n";
        echo "  -l LOG_FILE    输出日志文件或使用关键字 'syslog' 输出到 syslog\n";
        echo "  -p PREFIX      Optional prefix for functions/classes of PECL workers. PEAR requires a constant be defined in code.\n";
        echo "  -P PID_FILE    写入进程 ip 的文件\n";
        echo "  -u USERNAME    运行 worker 的  USERNAME\n";
        echo "  -v             增一个显示日志级别\n";
        echo "  -w DIR         woker 所在的目录, 默认为 ./workers. 如果你正在使用 PECL, 你可以提供一个逗号分隔的多个目录\n";
        echo "  -r NUMBER      每个 worker 最大工作迭代数量\n";
        echo "  -x SECONDS     每个worker最大生命周期(秒)\n";
        echo "  -Z             解析命令行和配置文件,然后转储它的屏幕和退出\n";
        echo "\n";
        exit;
    }
}
############################################################################
Fork::run();
############################################################################
############################################################################
#
# 脚本默认模拟如下工作:
#
# (说明: 大家根据自己的理解进行调试,目的只有一个就是验证如下这个想法正确与否)
#
# 在父进程发送SIGTERM信号给其派生的所有子进程(也就是使用posix_kill函数发送SIGTERM信号),
# 期间使用了pcntl_signal为父进程和子进程注册信号,并分别设定了对应的信号处理函数,
# 根据我理解的理论知识,如果没有设定SIGTERM信号处理函数,
# 默认情况下posix_kill会执行SIGTERM信号的原始行为即终止子进程,
# 但是如果设定了SIGTERM信号处理函数, posix_kill的SIGTERM信号的原始行为就会被改变
#
############################################################################
############################################################################
示例#6
0
 public function actionDeleteOld()
 {
     Event::model()->deleteAll('date < date_sub(utc_timestamp(), interval 4 hour)');
     Fork::model()->deleteAll('(select id from event where event.id = fork.event_id) is null');
 }
示例#7
0
 /**
  * @param Fork $fork
  * @param int $signal
  */
 public function sendSignal(Fork $fork, $signal)
 {
     posix_kill($fork->getPid(), $signal);
 }