[英]PHP Fatal error: Class 'Threaded' not found in C:\xampp\htdocs\
I am trying to use pthreads in php using xampp. 我正在尝试使用xampp在php中使用pthreads。 I'm using Windows. 我正在使用Windows。 Followed the steps provided in http://php.net/manual/en/class.thread.php for installation. 遵循http://php.net/manual/en/class.thread.php中提供的安装步骤。
This is the sample code I'm trying to compile: 这是我尝试编译的示例代码:
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();
This is the error I'm getting: 这是我得到的错误:
Fatal error: Class 'Threaded' not found in C:\\xampp\\htdocs\\practice\\thread1.php on line 2. 致命错误:在第2行的C:\\ xampp \\ htdocs \\ practice \\ thread1.php中找不到类'Threaded'。
This is the phpinfo page 这是phpinfo页面
I tried out the solutions given for the same from-> PHP pthreads: Fatal error: Class 'Thread' not found 我尝试了从-> PHP pthreads给出的相同解决方案:致命错误:找不到类'Thread'
I tried comparing the PHP Extension Build version(VC14) and the pthread version (it was found to be same). 我尝试比较PHP Extension Build版本(VC14)和pthread版本(发现是相同的)。 Thread safety is also enabled. 线程安全也已启用。 Also I tried loading the pthread_VC2.dll
file into httpd.conf
for Apache server. 我也尝试将pthread_VC2.dll
文件加载到Apache服务器的httpd.conf
中。
But nothing worked. 但是没有任何效果。 Please provide me with a solution. 请给我一个解决方案。
The line 线
class Task extends Threaded
should be changed to 应该更改为
class Task extends Thread
as shown in the first example 如第一个示例所示
class workerThread extends Thread
on the PHP.net Site 在PHP.net网站上
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.