I want to run PHP Thread class code on Windows. I tried some manual installation guides like e.g. this one but they didn't work. PHP cannot load the pthreads DLL even though the file exists at this location:
PHP Warning: PHP Startup: Unable to load dynamic library 'php_pthreads.dll' (tried: C:\xampp\php\ext\php_pthreads.dll (The specified module could not be found), C:\xampp\php\ext\php_php_pthreads.dll.dll (The specified module could not be found)) in Unknown on line 0
I downloaded php_pthreads-3.1.6-7.0-ts-vc14-x64.zip. My PHP version is: PHP 8.1.6 (cli) (built: May 11 2022 08:55:59) (ZTS Visual C++ 2019 x64)
. Generally I'm still not entirely sure which pthread
version to select since there are many choices here. Are any of them even going to work since they seem a bit outdated? My phpinfo
says:
Can I maybe just use Windows threads since they are already available on my system?
After the pthreads installation, when I run my Thread class example code
<?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();
?>
I still get the warning above and the following error:
PHP Fatal error: Uncaught Error: Class "Thread" not found
What am I doing wrong? Is there maybe a way to do it with less "manual" effort in e.g. 1 composer
command or an easier way to get threading working?