Witam
Chciałem użyć wielowątkowości w PHP 5.6.3
Zainstalowałem wszystko i napisałem skrypt.
Wszystko pięknie ładnie ale niestety wywala mi błąd
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)
#2 {main}
thrown in C:\xampp\htdocs\test\Benchmark.php on line 34
jak rozwiązać problem "usuwania" wątków tak aby mozna wykonywać np po 100 zadań jednocześnie w nieskończoność i aby skrypt usuwał te juz wykonane.
Może potrzeba czegoś innego niz czysty php thread?
<?php
$flaga=0;
//ini_set('memory_limit', '2M');
//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;
}
public function run () {
$this->data = th($this->ip);
$this->kill;
}
}
for($a=0;$a<=2000;$a=$a+100)//dowolna wartośc wykonywana w krokach co 100 wątków
{$zm[]=th_($a);
echo_($zm);
unset($zm);
}
function th_($co)
{$threads = [];
for($a=0;$a<=100;$a++)
{
$thread = new CheckIpThread($co+$a);
$thread->ip=($co+$a);
$threads []= $thread;
$thread->start();
$flaga=1;
}
foreach ($threads as $thread) {
$thread->join();
}
$zm=[];
foreach ($threads as $thread) {
$zm[]=($thread->data);
}
unset($thread);
//$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();
}
?>