multithreading - PHP thread don't work -
i use php_thread multithreading. http://php.net/manual/en/class.thread.php
installation successful got bad result
my code here :
<?php class workerthread extends thread { public function __construct($i){ $this->i=$i; } public function run(){ ($i=0; $i < 3; $i++) { echo "thread-".$this->i."=>".$i."<br/>"; } } } for($i=0;$i<2;$i++){ $workers[$i]=new workerthread($i); $workers[$i]->start(); } ?>
result:
thread-0=>0 thread-0=>1 thread-0=>2 thread-1=>0 thread-1=>1 thread-1=>2
the function not realize "multithreading". ?
avoid having echo in run function. can generates bugs , stuck workers in infinite loops.
let threads come join(). there, retrieve datas , have echo.
Comments
Post a Comment