facebook twitter hatena line email

Php/curl/zend http client速度比較

提供: 初心者エンジニアの簡易メモ
2017年11月29日 (水) 19:05時点におけるAdmin (トーク | 投稿記録)による版 (Admin がページ「Php/curl zend http client速度比較」を「Php/curl/zend http client速度比較」に、リダイレクトを残さずに移動しました)

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

結果

curl,zend_http_cilent,http_clientを比較した結果はcurlが最速でした。
検証端末はcentos5 cpu:2G memory:2G ADSLです。
それぞれ50回計測してます。

curl

  • wall_time 235.5238ms
  • peak_memory 66939.36
  • cpu 5079.22

zend_http_client

  • wall_time 290.34078ms
  • peak_memory 383597.44
  • cpu 18237.1

http_client

  • wall_time 307.44178ms
  • peak_memory 255329.28
  • cpu 17197.46

検証に使用したコード

/*
// curl
$chost = curl_init();
curl_setopt($chost, CURLOPT_URL, "http://www.google.com/");
    $options = array(
        CURLOPT_RETURNTRANSFER => true,         // return web page
        CURLOPT_HEADER         => false,        // don't return headers
        CURLOPT_FOLLOWLOCATION => true,         // follow redirects
        CURLOPT_ENCODING       => "",           // handle all encodings
        CURLOPT_USERAGENT      => "spider",     // who am i
        CURLOPT_AUTOREFERER    => true,         // set referer on redirect
        CURLOPT_CONNECTTIMEOUT => 120,          // timeout on connect
        CURLOPT_TIMEOUT        => 30,          // timeout on response
        CURLOPT_MAXREDIRS      => 10,           // stop after 10 redirects
//        CURLOPT_POST            => 1,            // i am sending post data
//        CURLOPT_POSTFIELDS     => $curl_data,    // this are my post vars
        CURLOPT_SSL_VERIFYHOST => 0,            // don't verify ssl
        CURLOPT_SSL_VERIFYPEER => false,        //
        CURLOPT_VERBOSE        => 1                //
    ); 
    
curl_setopt_array($chost,$options); 
$result = curl_exec($chost);
$code = curl_getinfo($chost, CURLINFO_HTTP_CODE);
curl_close($chost);
// echo print_r($result,1);
*/

/*
// zend_http_request
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(dirname(__FILE__) . '/../../library'),
    get_include_path(),
)));
$url = "http://www.google.com/";
require_once 'Zend/Http/Client.php';
require_once 'Zend/Http/Client/Adapter/Exception.php';
// Http_Clientロード
$client = new Zend_Http_Client();
try {
    $client->setUri($url);
    $client->setConfig(array(
     'maxredirects' => 10,
     'timeout'      => 30
    ));
    // GET リクエストを実行します
    $response = $client->request();
    // POST リクエストを実行します
    //$response = $client->request('POST');
} catch (Zend_Http_Client_Adapter_Exception $e) {
    // handle the error
    error_log($e);
}
// echo print_r($response,1);
*/
// http_client
require_once "HTTP/Client.php";
$login_url = "http://www.google.com/";
$client =& new HTTP_Client(); 
$client->get($login_url); 
$response = $client->currentResponse();
// echo print_r($response,1);