Witam
Mam taki kod
<?php
//ini_set('memory_limit', '2000M');nic nie daje
set_time_limit(0);
ini_set('display_errors', 0);
class CheckIpThread extends Thread {
private $ip;
public $data = null;
public function __construct ($ip_to_check) {
$this->ip = $ip_to_check;//ma byc get_headres($ip_to_check);
}
public function run () {
$this->data = th($this->ip);
$this->kill;//to nie działa
}
}
////.pobieram tablice ip
for($a=0;$a<=2000;$a=$a+100)// wartośc wykonywana w krokach co 100 wątków
{$zm[]=th_($a);//ma być $moje_ip[$a]
echo_($zm);//tymczasowo do testowania
unset($zm);//tu tez nic z tego
}
function th_($co)
{$threads = [];
for($a=0;$a<=100;$a++)
{
$thread = new CheckIpThread($co+$a);//$co[$a]
$thread->ip=($co+$a);//$co[$a]
$threads []= $thread;
$thread->start();
}
foreach ($threads as $thread) {
$thread->join();
}
$zm=[];
foreach ($threads as $thread) {
$zm[]=($thread->data);
}
unset($thread);//nie działa
//$thread->exit();
return $zm;
}
function th($wsad)
{return $wsad;//
}
function echo_($tekst,$def=0)//LIVE VIEV
{
ob_flush();
flush();
//usleep(200);
if($def===0)
{var_dump($tekst);}
if($def===1)
{echo($tekst);}
echo"</br>";
ob_end_flush();
ob_clean();
}
?>
Jeżeli gdzieś walnąłem literówkę w kodzie to przepraszam ale ogólnie to ma tak wyglądać.
Niestety kończy się to takim błędem.
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'pthreads has detected that the CheckIpThread could not be started, the system lacks the necessary resources or the system-imposed limit would be exceeded' in C:\xampp\htdocs\test\Benchmark.php:34
Stack trace:
#0 C:\xampp\htdocs\test\Benchmark.php(34): Thread->start()
#1 C:\xampp\htdocs\test\Benchmark.php(22): th_(900)
Czy mógłby mi ktoś pomóc to jakoś "opakować" żeby działało i żeby te wątki usuwać po zrobieniu 100 przejść.
Wiem że są jakieś workery i coś tam jeszcze w tej bibliotece ale za cieńki jestem żeby to ogarnąć.