PHP 线程 - 运行 方法未被调用
PHP thread - run method not being called
出于某种原因,我的 运行 方法没有被调用?有什么地方出错了吗?
<?php
class WorkerThread extends Thread
{
private $i = 0;
public function __construct( $i )
{
$this->i = $i;
}
public function run()
{
$a = 0;
while( $a < 100 )
{
file_put_contents( "test" . $this->i . ".txt", $a, FILE_APPEND );
sleep( 5 );
}
}
}
$workers = array();
for ( $i = 0; $i < 3; $i++ )
{
$workers[ $i ] = new WorkerThread( $i );
$workers[ $i ]->start();
}
?>
在 while 循环中,$a
永远不会改变并导致无限循环(它始终等于零)。
出于某种原因,我的 运行 方法没有被调用?有什么地方出错了吗?
<?php
class WorkerThread extends Thread
{
private $i = 0;
public function __construct( $i )
{
$this->i = $i;
}
public function run()
{
$a = 0;
while( $a < 100 )
{
file_put_contents( "test" . $this->i . ".txt", $a, FILE_APPEND );
sleep( 5 );
}
}
}
$workers = array();
for ( $i = 0; $i < 3; $i++ )
{
$workers[ $i ] = new WorkerThread( $i );
$workers[ $i ]->start();
}
?>
在 while 循环中,$a
永远不会改变并导致无限循环(它始终等于零)。