本文整理汇总了PHP中Thread::isAlive方法的典型用法代码示例。如果您正苦于以下问题:PHP Thread::isAlive方法的具体用法?PHP Thread::isAlive怎么用?PHP Thread::isAlive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thread
的用法示例。
在下文中一共展示了Thread::isAlive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: paralel
<?php
require_once 'php-thread-master/Thread.php';
// test to see if threading is available
/*if( ! Thread::available() ) {
die( 'Threads not supported' );
}*/
// function to be ran on separate threads
function paralel($_limit, $_name)
{
for ($index = 0; $index < $_limit; $index++) {
echo 'Ahora corriendo hilo ' . $_name . PHP_EOL;
sleep(1);
}
}
// create 2 thread objects
$t1 = new Thread('paralel');
$t2 = new Thread('paralel');
// start them
$t1->start(10, 't1');
$t2->start(10, 't2');
// keep the program running until the threads finish
while ($t1->isAlive() && $t2->isAlive()) {
sleep(1);
}
示例2: 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";