【发布时间】:2017-08-16 15:06:05
【问题描述】:
我正在尝试使用 xampp 在 php 中使用 pthreads。我正在使用 Windows。按照http://php.net/manual/en/class.thread.php 中提供的步骤进行安装。
这是我正在尝试编译的示例代码:
class Task extends Threaded
{
public $response;
public function someWork()
{
$content = file_get_contents('http://google.com');
preg_match('~<title>(.+)</title>~', $content, $matches);
$this->response = $matches[1];
}
}
$task = new Task;
$thread = new class($task) extends Thread {
private $task;
public function __construct(Threaded $task)
{
$this->task = $task;
}
public function run()
{
$this->task->someWork();
}
};
$thread->start() && $thread->join();
var_dump($task->response);
//phpinfo();
这是我得到的错误:
致命错误:未找到“线程”类 C:\xampp\htdocs\practice\thread1.php 在第 2 行。
我尝试了相同的解决方案来自-> PHP pthreads: Fatal error: Class 'Thread' not found
我尝试比较 PHP Extension Build 版本(VC14)和 pthread 版本(发现是相同的)。线程安全也被启用。我还尝试将 pthread_VC2.dll 文件加载到 Apache 服务器的 httpd.conf 中。
但没有任何效果。请给我一个解决方案。
【问题讨论】:
-
你扩展了错误的类
Threaded !=Thread -
@MasivuyeCokile 即使我将其更改为 Thread,我也遇到了同样的错误。