/** * */ public function testMultiRequest() { $multi = new dHttp\Client(); $response_array = $multi->multi([new dHttp\Client('http://php.net', [CURLOPT_FOLLOWLOCATION => true]), new dHttp\Client('http://www.python.org/', [CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1', CURLOPT_TIMEOUT => 10, CURLOPT_FOLLOWLOCATION => true])]); /* @var $item \dHttp\Response */ foreach ($response_array as $item) { self::assertInstanceOf('dHttp\\Response', $item); self::assertEquals($item->getCode(), 200); } }
} return $local_result; }; $multi = new dHttp\Client(); $used_links = array(); foreach ($params as $url) { $url = trim($url); if(!in_array($url,$used_links)) { $resp_once[] = new dHttp\Client($url, array( CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_HEADER => TRUE, CURLOPT_TIMEOUT_MS => 120000, CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_IPRESOLVE => 'CURL_IPRESOLVE_V4', CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5' )); $used_links[] = $url; } } $response_array = $multi->multi($resp_once); foreach($response_array as $item) { $result[] = $callback($item->getRaw(),$item->getUrl(),$item->getCode(),$target); } echo json_encode($result); //echo '<strong>Время выполнения скрипта: ' . (microtime(true) - $start) . ' сек.</strong>';
// Get response body $resp->getBody(); // Get request errors $resp->getErrors(); /* * Simple post request */ $resp = $http->post(['field1' => 'value1', 'field2' => 'value2']); $resp->getRaw(); // Return response headers $resp->getHeaders(); // Return a specific (text/html; charset=utf-8) $resp->getHeader('Content-Type'); /** * Another way of setting. * Output response */ $http = new dHttp\Client(); $http->addOptions([CURLOPT_RETURNTRANSFER => false])->setUserAgent('Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1')->setCookie('/tmp/cookies.txt')->setUrl('http://website.com')->get(); /** * Use multi curl */ $multi = new dHttp\Client(); $response_array = $multi->multi([new dHttp\Client('http://website1.com'), new dHttp\Client('http://website2.com', [CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1', CURLOPT_TIMEOUT => 5])]); foreach ($response_array as $item) { $resp->getCode(); } /** * Get cURL version */ \dHttp\Client::v();