Here's the the simple demonstrative snippet:
<?php
class WorkerThreads extends Thread
{
private $workerId;
private $url;
public function __construct($string)
{
$this->url = $string;
}
public function run()
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $this->url);
if ($this->post) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->post);
}
$response = curl_exec($curl);
//echo $response;
curl_close($curl);
}
}
$data = file('urls.txt');
$data_size = count($data);
// Worker pool
$workers = [];
$t_count = 100;
$flag = 1;
$k = 0;
while($flag === 1)
{
$c_w = count($workers);
if($c_w < $t_count)
{
for($i = $c_w; $i<$t_count - $c_w;$i++)
{
if($k >= $data_size)
{
$flag = 0;
break;
}
$url = explode("|",$data[$k]);
$workers[$i] = new WorkerThreads($url[0]);
echo $k." ".$url[0]."\n";
$workers[$i]->start();
$k++;
}
}
$c_w = count($workers);
for($i=0;$i<$c_w;$i++)
{
if($workers[$i]->join())
{
//echo "joining $i\n";
unset($workers[$i]);
}
}
}
?>
The problem that I can't understand is that on php 7x86 I always getting this error:
Fatal error: Uncaught RuntimeException: cannot start WorkerThreads, out of reso
rces in C:\Users\alex\Desktop\test.php:56
Stack trace:
#0 C:\Users\alex\Desktop\test.php(56): Thread->start()
#1 {main}
thrown in C:\Users\alex\Desktop\test.php on line 56
For some reason this not appear in php 7 x64 version (with same ini settings). Why is that happening? Thanks!
upd: Also there is no info about this case on google. Asked it in few communities, but no one seems to know about how to fix this or even why exception raises.