<commit_before><?php

namespace Buzz\Client;

use Buzz\Message;

class MultiCurl extends Curl implements BatchClientInterface
{
    protected $queue = array();

    public function __construct()
    {
        $this->curl = curl_multi_init();
    }

    public function send(Message\Request $request, Message\Response $response, $curl = null)
    {
        $this->queue[] = array($request, $response, $curl);
    }

    public function flush()
    {
        foreach ($this->queue as $i => $queue) {
            list($request, $response, $curl) = $queue;

            if (null === $curl) {
                $curl = $this->queue[$i][2] = static::createCurlHandle();
            }

            static::setCurlOptsFromRequest($curl, $request);
            curl_multi_add_handle($this->curl, $curl);
        }

        $active = null;
        do {
            $mrc = curl_multi_exec($this->curl, $active);
        } while (CURLM_CALL_MULTI_PERFORM == $mrc);

        while ($active && CURLM_OK == $mrc) {
            if (-1 != curl_multi_select($this->curl)) {
                do {
                    $mrc = curl_multi_exec($this->curl, $active);
                } while (CURLM_CALL_MULTI_PERFORM == $mrc);
            }
        }

        foreach ($this->queue as $queue) {
            list($request, $response, $curl) = $queue;
            $response->fromString(curl_multi_getcontent($curl));
            curl_multi_remove_handle($this->curl, $curl);
        }

        $this->queue = array();
    }

    public function __destruct()
    {
        curl_multi_close($this->curl);
    }
}<commit_msg>Fixed parsing of multi response in multi curl client.<commit_after><?php

namespace Buzz\Client;

use Buzz\Message;

class MultiCurl extends Curl implements BatchClientInterface
{
    protected $queue = array();

    public function __construct()
    {
        $this->curl = curl_multi_init();
    }

    public function send(Message\Request $request, Message\Response $response, $curl = null)
    {
        $this->queue[] = array($request, $response, $curl);
    }

    public function flush()
    {
        foreach ($this->queue as $i => $queue) {
            list($request, $response, $curl) = $queue;

            if (null === $curl) {
                $curl = $this->queue[$i][2] = static::createCurlHandle();
            }

            static::setCurlOptsFromRequest($curl, $request);
            curl_multi_add_handle($this->curl, $curl);
        }

        $active = null;
        do {
            $mrc = curl_multi_exec($this->curl, $active);
        } while (CURLM_CALL_MULTI_PERFORM == $mrc);

        while ($active && CURLM_OK == $mrc) {
            if (-1 != curl_multi_select($this->curl)) {
                do {
                    $mrc = curl_multi_exec($this->curl, $active);
                } while (CURLM_CALL_MULTI_PERFORM == $mrc);
            }
        }

        foreach ($this->queue as $queue) {
            list($request, $response, $curl) = $queue;
            $response->fromString($this->getLastResponse(curl_multi_getcontent($curl)));
            curl_multi_remove_handle($this->curl, $curl);
        }

        $this->queue = array();
    }

    public function __destruct()
    {
        curl_multi_close($this->curl);
    }
}
{'fraction_non_alphanumeric': 0.14391143911439114, 'fraction_numerical': 0.0012300123001230013, 'mean_word_length': 2.0834123222748815, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1336478', 'n_tokens_mistral': 1026, 'n_tokens_neox': 955, 'n_words': 194}