note 116503 deleted from class.thread by salathe
| From: | salathe@php.net | Date: | Tue, 02 Aug 2016 12:14:35 +0000 |
| Subject: | note 116503 deleted from class.thread by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206188@lists.php.net to get a copy of this message | ||
Note Submitter: 66377393 at qq dot com
----
<?php
class demo extends Thread{
public $num = 0;
public function __construct($num){
$this->num = $num+200;
}
public function run(){
//彿§è¡startæ¹æ³æ¶ï¼run伿§è¡ï¼æä»¥æ²¡æç´æ¥è°ç¨runçæ¹æ³
return $this->num;
}
}
//æ¶é´è®¡ç®å¼å§
$t = microtime(true);
for($i = 0 ;$i < 10 ; $i++){
//åå»ºçº¿ç¨æ±
$pool[] = new demo($i);
}
foreach($pool as $work){
//å¨ç¬ç«çº¿ç¨ä¸æ§è¡ run æ¹æ³
$work->start();
}
foreach($pool as $key=>$value){
//对象æ¯å¦æ£å¨è¿è¡
while($value->isRunning()){
usleep(10);
}
//让å½åæ§è¡ä¸ä¸æçå¾
被å¼ç¨çº¿ç¨æ§è¡å®æ¯
if($value->join()){
$row[$key] = $value->num;
}
}
//æ¶é´è®¡ç®ç»æ
$e = microtime(true);
var_dump($row);
echo '<br />';
echo ($e-$t);