如何在Windows上使用PHP中的线程
我想在PHP中使用线程。我正在使用windows。需要做些什么才能做到这一点。这是我正在运行的代码如何在Windows上使用PHP中的线程,php,multithreading,installation,Php,Multithreading,Installation,我想在PHP中使用线程。我正在使用windows。需要做些什么才能做到这一点。这是我正在运行的代码 <?php class AsyncOperation extends Thread { public function __construct($arg){ $this->arg = $arg; } public function run(){ if($this->arg){ printf("Hello %s\n", $this->
<?php
class AsyncOperation extends Thread {
public function __construct($arg){
$this->arg = $arg;
}
public function run(){
if($this->arg){
printf("Hello %s\n", $this->arg);
}
}
}
$thread = new AsyncOperation("World");
if($thread->start())
$thread->join();
?>
当我运行代码时,它会显示
致命错误:在第2行的D:\xampp\htdocs\my.php中找不到类“Thread”
提前感谢您的系统上似乎没有安装pthreads扩展。 它是一个定制的PHP扩展,默认情况下不是与XAMPP一起安装的。 去拿吧 您可以在上找到Windows的pthread版本 将
pthreadVC2.dll
添加到与php.exe
相同的目录中,例如C:\xampp\php
将php_pthreads.dll
添加到php扩展文件夹,例如C:\xampp\php\ext
然后通过在extensions部分添加extension=php_pthreads.dll
来修改php.ini
您发布的代码是一个基本示例,在安装扩展时,它应该可以立即运行
上面还有一个糖果:
线程
是一个PECL软件包-您安装了它吗?我只是照你说的做了。但仍然显示出相同的错误。我还需要安装其他东西吗?我使用的是XAMPP 5.6.3和下载的php_pthreads-2.0.9-5.6-ts-vc11-x86.zip,并在特定文件夹中粘贴了两个指定的文件。是的。您需要修改php.ini-扩展部分,并在其中包含php_ptreads.dll。只需在php.ini中搜索“.dll”。把它加在底部。谢谢。解决了这个问题。不得不将“extension=php\u pthreads.dll”添加到php.ini我也有同样的问题,但添加extension=php\u pthreads.dll并没有解决这个问题