例子程序
<?php
/*
haring symbols 101
* @NOTE Thread::fetch was never included in a release and was superceeded by object handlers
* pthreads allows read access to thread data from any context
pthreads allows write access to thread data from any context
carry on reading ...
work in progress ...
*/
class TestObject {
public $val;
}
class Fetching extends Thread {
public function run(){
/*
* of course ...
*/
$this->sym = 10245;
$this->arr = array(
"1", "2", "3"
);
echo '6'.chr(10);
省略内容可以输出正确的结果, pthread 环境安装没问题在thinkphp里的 代码如下:
<?php
namespace Home\Controller;
use Thread;
class Computer extends Thread {
public $id;
public $runing = false;
public $params = null;
public function __construct($id) {
$this->id = $id;
$this->runing = true;
}
public function run() {
while ($this->runing) {
if (is_null($this->params)) {
echo "线程[{$this->id}]等待任务...\n";
} else {
echo "线程[{$this->id}] 收到任务参数::{$this->params}.\n";
$this->params = null;
}
sleep(1);
}
}
}提示找不到 Class 'Thread' not found, 搞不懂为啥???最佳答案