Веб-приложение приостановлено (зависает), пока работает php curl_multi_exec

Что не так? php, mysql, apache под MAMP: все работает хорошо! но на время выполнения этого скрипта (даже с 1-3 ссылками) целые запросы страниц текущего сайта приостанавливаются (замораживаются). Когда multi curl завершается, все запросы замороженных страниц загружаются немедленно.

class Web_Processor {
    protected $conf;

    /** @var \Web_Response[]*/
    protected $response = array();

    public function __construct(array $urls, Web_Configurator &$conf){//multi thread
        $this->conf = &$conf;

        $_autoreferrer          = Kohana::$config->load('admin_/webloader.curl_autoreferer-X-val');
        $_follow_loc            = Kohana::$config->load('admin_/webloader.curl_followlocation-X-val');
        $_max_redirects         = Kohana::$config->load('admin_/webloader.curl_maxredirs-X-val');
        $_connection_timeout    = Kohana::$config->load('admin_/webloader.curl_connectiontimeout-X-val');
        $_curl_timeout          = Kohana::$config->load('admin_/webloader.curl_timeout-X-val');
        //
        $_autoreferrer          = (bool) $_autoreferrer; //true/false
        $_follow_loc            = (bool) $_follow_loc; //true/false
        $_max_redirects         = (int) $_max_redirects; //5
        $_connection_timeout    = (int) $_connection_timeout; //20 
        $_curl_timeout          = (int) $_curl_timeout; //25

        $cmh = curl_multi_init();

        // multicurl tasks
            $tasks = array();


        foreach ($urls as $url) {
            // thread
            $ch = curl_init($url);  //URL

            curl_setopt($ch, CURLOPT_AUTOREFERER, $_autoreferrer);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $_follow_loc);
            curl_setopt($ch, CURLOPT_MAXREDIRS, $_max_redirects);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);    //FIX "HTTPS://"
            curl_setopt($ch, CURLOPT_HEADER, 0);                
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $_connection_timeout);                   curl_setopt($ch, CURLOPT_TIMEOUT, $_curl_timeout);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,    true);
            curl_setopt($ch, CURLINFO_HTTP_CODE,        true);
            curl_setopt($ch, CURLOPT_PROXY,         $this->conf->getProxyIP().":".$this->conf->getProxyPort());     //'xxx.xxx.xxx.xxx' : 'xxx'
            curl_setopt($ch, CURLOPT_USERAGENT,     $this->conf->getUserAgent());                                   //Opera/9.80 (Windows NT 5.1; U; en) Presto/2.9.168 Version/11.51
            if($referrer = $this->conf->getReferrer() !== false){                                                   //REFERRER
                curl_setopt($ch, CURLOPT_REFERER, $referrer);
            }

            // thread descriptior to tasks array
            $tasks[$url] = $ch;
            // thread description to multicurl
            curl_multi_add_handle($cmh, $ch);
        }

// active threads count
        $active = null;
// thread execution
        do {
            $mrc = curl_multi_exec($cmh, $active);
        }
        while ($mrc == CURLM_CALL_MULTI_PERFORM);


        while ($active && ($mrc == CURLM_OK)) {

            if (curl_multi_select($cmh) != -1) {

                do {
                    $mrc = curl_multi_exec($cmh, $active);

                    $info = curl_multi_info_read($cmh);

                    if ($info['msg'] == CURLMSG_DONE) {
                        $ch = $info['handle'];

                        $url = array_search($ch, $tasks);
                        // getting content
                        $tasks[$url] = curl_multi_getcontent($ch);
                        $this->response[] = new Web_Response(
                            $url,
                            curl_getinfo($ch),                  //headers
                            curl_multi_getcontent($ch),         //response body
                            curl_errno($ch),                    //error code
                            curl_error($ch)                     //error message
                        );
                        // deleting thread from multicurl
                        curl_multi_remove_handle($cmh, $ch);
                        // closing thread
                        curl_close($ch);
                    }
                }
                while ($mrc == CURLM_CALL_MULTI_PERFORM);
            }
        }

// closing multicurl
        curl_multi_close($cmh);

    }

    public function results(){
        return $this->response;
    }
}

person LINKeRxUA    schedule 02.04.2015    source источник
comment
Очень похоже на блокировку сеанса. Исследуйте это. Если это не так, дайте мне знать.   -  person deceze♦    schedule 02.04.2015
comment
@deceze, ты прав. Я читаю сеанс, прежде чем запустить этот код. (используйте фреймворк Kohana). Когда я комментирую запрос к Session::instance() - все отлично работает. Благодарю вас! Ты толкнул меня в правильном направлении!   -  person LINKeRxUA    schedule 02.04.2015
comment
исправлено добавлением 'session_write_close();' перед выполнением завитка   -  person LINKeRxUA    schedule 02.04.2015
comment
@deceze опубликуйте, пожалуйста, «session_write_close ()» в качестве ответа на вопрос «Я могу закрыть вопрос».   -  person LINKeRxUA    schedule 02.04.2015
comment
Ваш вопрос уже закрыт.   -  person deceze♦    schedule 02.04.2015