当前位置: 首页>>代码示例>>PHP>>正文


PHP Thread::start方法代码示例

本文整理汇总了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);
 }
开发者ID:stof,项目名称:pthreads-polyfill,代码行数:10,代码来源:ThreadTest.php

示例2: testThreadAlreadyJoined

 /**
  * @expectedException RuntimeException
  */
 public function testThreadAlreadyJoined()
 {
     $thread = new Thread();
     $this->assertTrue($thread->start());
     $this->assertTrue($thread->join());
     $this->assertFalse($thread->join());
 }
开发者ID:krakjoe,项目名称:pthreads-polyfill,代码行数:10,代码来源:ThreadTest.php

示例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;
 }
开发者ID:TylerAndrew,项目名称:Steadfast2,代码行数:8,代码来源:Thread.php

示例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();
 }
开发者ID:xingcuntian,项目名称:php-thread,代码行数:15,代码来源:ThreadQueue.php

示例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();
         }
     }
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:10,代码来源:http.php

示例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();
     }
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:11,代码来源:node.php

示例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;
 }
开发者ID:Cecil107,项目名称:PocketMine-0.13.0,代码行数:11,代码来源:Thread.php

示例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);
     });
 }
开发者ID:domraider,项目名称:rxnet,代码行数:20,代码来源:RxThread.php

示例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);
     }
 }
开发者ID:koolkode,项目名称:async,代码行数:25,代码来源:ThreadPool.php

示例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";
开发者ID:sergio11,项目名称:teVeo,代码行数:20,代码来源:testThread.php

示例11: execute

 /**
  * Start the thread
  *
  * @throws \RuntimeException
  */
 public function execute()
 {
     $this->args = func_get_args();
     return parent::start();
 }
开发者ID:byjg,项目名称:phpthread,代码行数:10,代码来源:PThreadHandler.php

示例12: start

 public final function start($options = PTHREADS_INHERIT_ALL)
 {
     ThreadManager::getInstance()->add($this);
     return parent::start($options);
 }
开发者ID:boybook,项目名称:PocketMine-MP,代码行数:5,代码来源:Thread.php

示例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));
开发者ID:marcosrachid,项目名称:pthreads,代码行数:30,代码来源:Benchmark.php

示例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;
 }
开发者ID:xingcuntian,项目名称:thread,代码行数:17,代码来源:Dispatcher.php

示例15: start

 /**
  * Spawns the module's logic in a new worker thread.
  */
 public function start()
 {
     $stopRequested = false;
     parent::start(PTHREADS_INHERIT_NONE);
 }
开发者ID:nagendragpu,项目名称:facebook-bot,代码行数:8,代码来源:ModuleAbstract.php


注:本文中的Thread::start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。