本文整理汇总了PHP中Worker类的典型用法代码示例。如果您正苦于以下问题:PHP Worker类的具体用法?PHP Worker怎么用?PHP Worker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Worker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _startWorker
/**
* Start a worker
*/
protected function _startWorker()
{
$worker = new Worker();
$worker->logLevel = $this->logLevel;
fwrite(STDOUT, '*** Starting scheduler worker ' . PHP_EOL);
$worker->work($this->interval);
}
示例2: addWorker
/**
* Adds a worker to the action.
*
* @param Worker $worker
*
* @return Action
* @throws \Exception
*/
public function addWorker($worker)
{
if (!$worker instanceof Worker) {
throw new \Exception('$worker is not an instance of Worker');
}
$this->workerList[$worker->getId()] = $worker;
return $this;
}
示例3: testGetStacked
public function testGetStacked()
{
$worker = new Worker();
$work = new WorkerTestWork();
$worker->stack($work);
$this->assertEquals(1, $worker->getStacked());
$worker->stack($work);
$this->assertEquals(2, $worker->getStacked());
}
示例4: testWorkerNoJobs
/**
* When the timeout passed to ::processOne() is 0 and there are no jobs it should return quitely.
* @throws Exception\WorkerException
*/
public function testWorkerNoJobs()
{
$testWorkerRuns = $this;
$tube = 'worker_tube_' . rand(53, 504);
$data = 'worker_value_' . rand(95, 3000);
$pheanstalk = new Pheanstalk(self::SERVER_HOST, self::SERVER_PORT);
$worker = new Worker(self::SERVER_HOST, self::SERVER_PORT);
$worker->register($tube, function (Job $job) use($testWorkerRuns, $data) {
$testWorkerRuns->assertEquals($data, $job->getData());
});
$processedJob = $worker->processOne(0);
$stats = $pheanstalk->statsTube($tube);
$this->assertEquals($stats['total-jobs'], 0);
}
示例5: startWorkers
private function startWorkers()
{
$wrapper = realpath(__DIR__ . '/../../../../bin/phpunit-wrapper');
for ($i = 1; $i <= $this->options->processes; $i++) {
$worker = new Worker();
if ($this->options->noTestTokens) {
$token = null;
} else {
$token = $i;
}
$worker->start($wrapper, $token);
$this->streams[] = $worker->stdout();
$this->workers[] = $worker;
}
}
示例6: testWorkerGc
public function testWorkerGc()
{
$worker = new Worker();
$work = new WorkerTestWork();
$worker->start();
$worker->stack($work);
$work->synchronized(function ($work) {
if (!$work->isGarbage()) {
$work->wait();
}
}, $work);
$this->assertEquals($worker->collect(function ($task) {
return false;
}), 1);
$this->assertEquals($worker->collect(function ($task) {
return $task->isGarbage();
}), 0);
}
示例7: server
{
echo $user->getUsername();
}
public function server()
{
$ws_worker = new \Worker("websocket://0.0.0.0:2346");
$ws_worker->count = 4;
$ws_worker->onMessage = function ($connection, $data) {
$connection->send('hello ' . $data);
};
示例8: saveWorker
/**
* Save or update worker
* @param Worker $worker
* @return Worker
*/
public function saveWorker(Worker $worker)
{
if (is_null($worker->getId())) {
$query = $this->db->prepare("INSERT INTO workers (host, port, type, status) VALUES (?, ?, ?, ?)");
$query->execute([$worker->getHost(), $worker->getPort(), $worker->getType(), $worker->getStatus()]);
$worker->setId($this->db->lastInsertId());
} else {
$query = $this->db->prepare("UPDATE workers SET host = ?, port = ?, type = ?, status = ? WHERE id = ?");
$query->execute([$worker->getHost(), $worker->getPort(), $worker->getType(), $worker->getStatus(), $worker->getId()]);
}
return $worker;
}
示例9: fillData
public function fillData(ShiftAssignmentView $shiftassignment)
{
$this->workerid = $shiftassignment->workerid;
$this->stationid = $shiftassignment->stationid;
$this->expoid = $shiftassignment->expoid;
$this->expo = $shiftassignment->expoTitle;
$this->station = $shiftassignment->location . " (" . $shiftassignment->stationTitle . ")";
$this->startTime = $shiftassignment->startTime;
$this->stopTime = $shiftassignment->stopTime;
$worker = Worker::selectID($shiftassignment->workerid);
$this->workerName = $worker->nameString2();
$this->workerEmail = $worker->email;
return $this;
}
示例10: createShiftCheckInHTMLList
function createShiftCheckInHTMLList($expoid, $stationid)
{
echo "<div id=\"workerlist_table\">\n";
echo "<form method=\"POST\" name=\"ShiftCheckIn_form\" action=\"ShiftCheckInAction.php?" . PARAM_LIST_INDEX . "=" . $stationid . "\">\n";
echo "<table>\n";
$shiftAssignmentList = ShiftAssignmentView::selectStation($expoid, $stationid);
$c = count($shiftAssignmentList);
$workerList = array();
for ($k = 0; $k < $c; $k++) {
$workerList[$k] = Worker::selectID($shiftAssignmentList[$k]->workerid);
}
usort($workerList, "WorkerCompare");
echo "<tr><td class=\"rowTitle\" colspan=\"4\">Supervisors</td></tr>\n";
$supervisors = 0;
for ($k = 0; $k < $c; $k++) {
if ($workerList[$k]->isSupervisor() && !$workerList[$k]->isDisabled) {
$ss = ShiftStatus::mostRecentStatus($workerList[$k]->workerid, $stationid, $expoid);
if (count($ss) > 0) {
$statusType = $ss->statusType;
} else {
$statusType = NULL;
}
makeShiftCheckInListHTMLRows($workerList[$k], $statusType);
$supervisors++;
}
}
if ($supervisors == 0) {
echo "<tr><td class=\"fieldError\" colspan=\"4\">There are currently no Supervisors assigned to this station.</td></tr>\n";
}
echo "<tr><td class=\"rowTitle\" colspan=\"4\">Crew</td></tr>\n";
$crew = 0;
for ($k = 0; $k < $c; $k++) {
if ($workerList[$k]->isCrewMember() && !$workerList[$k]->isDisabled) {
$ss = ShiftStatus::mostRecentStatus($workerList[$k]->workerid, $stationid, $expoid);
if (count($ss) > 0) {
$statusType = $ss->statusType;
} else {
$statusType = NULL;
}
makeShiftCheckInListHTMLRows($workerList[$k], $statusType);
$crew++;
}
}
// $k
if ($crew == 0) {
echo "<tr><td class=\"fieldError\" colspan=\"4\">There are currently no Crew assigned to this station.</td></tr>\n";
}
echo "</table></form></div><!-- workerlist_table -->\n";
}
示例11: postRelated
/**
* Show the form for creating a new resource.
* @param Request $request
* @return Response
*/
public function postRelated(Request $request)
{
$people = People::all();
$worker = Worker::all();
$ids = array();
for ($i = 0; $i < $worker->count(); $i++) {
for ($j = 0; $j < $people->count(); $j++) {
if ($people->get($j)->id == $worker->get($i)->people_id) {
$ids[] = $people->get($j)->id;
}
}
}
$people = People::whereNotIn('id', $ids)->get();
$branch = Branch::findOrFail($request->get('id'));
return view('admin.listpeople', compact('people', 'branch'));
}
示例12: searchWorkers
/**
* Поиск сотрудников
* @param string $query
* @param integer $limit
* @return \Elasticquent\ElasticquentResultCollection
*/
public function searchWorkers(string $query, int $limit = 10)
{
return Worker::searchByQuery(['match' => ['search' => ['query' => $query, 'operator' => 'and']]], null, null, $limit)->load('organization');
// $result = Worker::searchByQuery(
// ['match' => [
// 'search' => [
// 'query' => $query,
// 'operator' => 'and',
// ]
// ]],
//
// ['orgs' => [
// 'terms' => [
// 'field' => 'organization_id',
// 'size' => 10
// ],
// 'aggregations' => [
// 'fio' => [
// 'terms' => [
// 'field' => 'fio',
// ],
// 'aggregations' => [
// 'top' => [
// 'top_hits' => [
// 'size' => 1
// ]
// ]
// ]
// ]
// ]
// ]], null, 0
// );
//
// $ids = [];
// $aggregations = $result->getAggregations();
// foreach($aggregations['orgs']['buckets'] as $data) {
// foreach($data['fio']['buckets'] as $data2) {
// $ids[] = $data2['top']['hits']['hits'][0]['_id'];
// }
// }
// $ids = array_slice($ids, 0, 20);
//
// return Worker::whereIn('id', $ids)->with('organization')->get();
}
示例13: start
public function start($options = PTHREADS_INHERIT_ALL)
{
ThreadManager::getInstance()->add($this);
if (!$this->isRunning() and !$this->isJoined() and !$this->isTerminated() and !$this->isShutdown()) {
return parent::start($options);
}
return false;
}
示例14:
function __construct($config)
{
parent::__construct($config);
$this->register_handler("do_get_testsyncphp_thing_v1");
$this->register_handler("do_put_testsyncphp_thing_v1");
$this->register_handler("do_post_testsyncphp_thing_v1");
$this->register_handler("do_delete_testsyncphp_thing_v1");
}
示例15: release
protected function release()
{
if (count($this->sqlArray) > 0) {
$this->executeSql();
}
parent::release();
// TODO: Change the autogenerated stub
}