本文整理汇总了PHP中Thread::start方法的典型用法代码示例。如果您正苦于以下问题:PHP Thread::start方法的具体用法?PHP Thread::start怎么用?PHP Thread::start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thread
的用法示例。
在下文中一共展示了Thread::start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testThreadAlreadyJoined
/**
* @expectedException RuntimeException
*/
public function testThreadAlreadyJoined()
{
$thread = new Thread();
$this->assertEquals($thread->start(), true);
$this->assertEquals($thread->join(), true);
$this->assertEquals($thread->join(), false);
}
示例2: testThreadAlreadyJoined
/**
* @expectedException RuntimeException
*/
public function testThreadAlreadyJoined()
{
$thread = new Thread();
$this->assertTrue($thread->start());
$this->assertTrue($thread->join());
$this->assertFalse($thread->join());
}
示例3: start
public function start($options = PTHREADS_INHERIT_ALL)
{
ThreadManager::getInstance()->add($this);
if (!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()) {
return parent::start($options);
}
return false;
}
示例4: tick
/**
* Starts new threads if needed
*
* @return int queue size
*/
public function tick()
{
$this->cleanup();
if (count($this->threads) < $this->queueSize && count($this->jobs)) {
$this->threads[] = $szal = new Thread($this->callable);
$szal->start(array_shift($this->jobs));
}
usleep(ThreadQueue::TICK_DELAY);
return $this->queueSize();
}
示例5: run
function run()
{
while (true != $this->exit) {
$sock = socket_accept($this->ls);
if ($sock) {
$hs = new Thread(new HttpHandler($sock, $this->handler));
$hs->start();
}
}
}
示例6: start
static function start($transport, $nodename = null, $background = true)
{
$node = new LdwpNode();
if ($background) {
$t = new Thread($node);
$pid = $t->start();
console::writeLn("Forked with pid %d", $pid);
} else {
$node->threadmain();
}
}
示例7: start
public function start(int $options = PTHREADS_INHERIT_ALL)
{
ThreadManager::getInstance()->add($this);
if (!$this->isRunning() and !$this->isJoined() and !$this->isTerminated()) {
if ($this->getClassLoader() === null) {
$this->setClassLoader();
}
return parent::start($options);
}
return false;
}
示例8: handle
public function handle(\Thread $thread)
{
$thread->start();
echo "Start thread with ID {$thread->getCurrentThreadId()}\n";
return Observable::create(function (ObserverInterface $observer) use($thread) {
while ($thread->isRunning()) {
$this->loop->tick();
}
try {
echo "Thread finished\n";
$thread->join();
$observer->onNext(new Event('/thread/ok', $thread));
$observer->onCompleted();
} catch (\Exception $e) {
echo "Thread error\n";
$observer->onError($e);
}
unset($thread);
});
}
示例9: spawnWorker
/**
* {@inheritdoc}
*/
protected function spawnWorker() : Awaitable
{
if (self::$sharedWorkers === null) {
self::$sharedWorkers = [];
\register_shutdown_function(function () {
self::shutdownPool();
});
}
$index = self::$allocated++ % self::getMaxSize();
if (isset(self::$sharedWorkers[$index])) {
return new Success(self::$sharedWorkers[$index]);
}
try {
list($a, $b) = Socket::createPair();
$thread = new Thread($b, self::getComposerAutoloader());
$thread->start(\PTHREADS_INHERIT_INI);
return new Success(self::$sharedWorkers[$index] = new ThreadWorker($index, $a, $thread));
} catch (\Throwable $e) {
self::$allocated--;
return new Failure($e);
}
}
示例10: proceso
<?php
require "thread.php";
echo "Hola que talllll";
function proceso($tiempo, $resultado)
{
usleep($tiempo);
exit($resultado);
}
$thread1 = new Thread('proceso');
$thread2 = new Thread('proceso');
$thread3 = new Thread('proceso');
$thread1->start(3, 10);
$thread2->start(2, 40);
$thread3->start(1, 30);
while ($thread1->isAlive() || $thread2->isAlive() || $thread3->isAlive()) {
}
echo "Resultado del hilo 1 (debe ser 3): " . $thread1->getExitCode() . "\n";
echo "Resultado del hilo 2 (debe ser 2): " . $thread2->getExitCode() . "\n";
echo "Resultado del hilo 3 (debe ser 1): " . $thread3->getExitCode() . "\n";
示例11: execute
/**
* Start the thread
*
* @throws \RuntimeException
*/
public function execute()
{
$this->args = func_get_args();
return parent::start();
}
示例12: start
public final function start($options = PTHREADS_INHERIT_ALL)
{
ThreadManager::getInstance()->add($this);
return parent::start($options);
}
示例13: microtime
<?php
/**
* This file serves as a benchmark for pthreads initialization/destruction
* usage: php-zts examples/Benchmark.php [threads] [samples]
* threads - the number of threads to create, default=100
* samples - the number of times to run the test, default=5
*/
/**
* Nothing
*/
$max = @$argv[1] ? $argv[1] : 100;
$sample = @$argv[2] ? $argv[2] : 5;
printf("Start(%d) ...", $max);
$it = 0;
do {
$s = microtime(true);
/* begin test */
$ts = [];
while (count($ts) < $max) {
$t = new Thread();
$t->start();
$ts[] = $t;
}
$ts = [];
/* end test */
$ti[] = $max / (microtime(true) - $s);
printf(".");
} while ($it++ < $sample);
printf(" %.3f tps\n", array_sum($ti) / count($ti));
示例14: spawnWorker
private function spawnWorker()
{
$results = new SharedData();
$resultCodes = new SharedData();
$thread = new Thread($results, $resultCodes, $this->ipcUri);
if (!$thread->start()) {
throw new \RuntimeException('Worker thread failed to start');
}
$worker = new Worker();
$worker->id = $thread->getThreadId();
$worker->results = $results;
$worker->resultCodes = $resultCodes;
$worker->thread = $thread;
$this->pendingWorkers[$worker->id] = $worker;
$this->pendingWorkerCount++;
return $worker;
}
示例15: start
/**
* Spawns the module's logic in a new worker thread.
*/
public function start()
{
$stopRequested = false;
parent::start(PTHREADS_INHERIT_NONE);
}