A
A
astrotrain2016-01-31 15:33:04
PHP
astrotrain, 2016-01-31 15:33:04

Why is pthreads php 7.0.2 x86 running out of resources?

There is this code:

<?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]);

        }
    }


}

?>

For some reason, an exception is constantly thrown at startup:
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

But this is only in xampp and php 7 version x86, and in the x64 version everything is fine. What can be wrong? There is not much information on the topic. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nazar Mokrinsky, 2016-01-31
@nazarpc

https://github.com/krakjoe/pthreads/issues

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question