某テンプレートエンジンの各HTTPクライアントで100リクエスト投げた時のベンチマーク
大体3,4回目の結果を載っけてます。
環境:
$ \php -v PHP 5.3.2-1ubuntu4 with Suhosin-Patch (cli) (built: Apr 9 2010 08:23:39) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
$ pear list | grep Net_Socket Net_Socket 1.0.9 stable $ pear list -a | grep HTTP HTTP_Client 1.2.1 stable HTTP_Request 1.4.4 stable HTTP_Request2 0.5.2 alpha $ pear list -a | grep ZF INSTALLED PACKAGES, CHANNEL PEAR.ZFCAMPUS.ORG: ZF 1.10.5 stable $ pecl list | grep http pecl_http 1.6.6 stable
file_get_contents
$ cat file_get.php <?php for ($i=1; $i <=100; $i++) { file_get_contents('http://localhost/favicon.ico'); } $ time \php file_get.php real 0m0.107s user 0m0.044s sys 0m0.036s
pear/HTTP_Request
$ cat pear_httpRequest.php <?php require_once 'HTTP/Request.php'; for ($i=1; $i <=100; $i++) { $req = new HTTP_Request('http://localhost/favicon.ico'); $req->sendRequest(); } $ time \php pear_httpRequest.php real 0m0.212s user 0m0.148s sys 0m0.044s
pear/HTTP_Request2
$ cat pear_httpRequest2.php <?php require_once 'HTTP/Request2.php'; for ($i=1; $i <=100; $i++) { $req2 = new HTTP_Request2('http://localhost/favicon.ico'); $req2->send(); } $ time \php pear_httpRequest2.php real 0m0.190s user 0m0.160s sys 0m0.012s
ZFのZend_Http_Client
$ cat zf_http.php <?php require_once 'Zend/Http/Client.php'; for ($i=1; $i <=100; $i++) { $client = new Zend_Http_Client('http://localhost/favicon.ico'); $client->request(); } $ time \php zf_http.php real 0m0.267s user 0m0.172s sys 0m0.036s
CURL(sudo apt-get php5-curlしたやつ)
$ cat cURL.php <?php for ($i=1; $i <=100; $i++) { $fh = fopen('/tmp/null', 'w'); $ch = curl_init('http://localhost/favicon.ico'); curl_setopt($ch, CURLOPT_FILE, $fh); curl_exec($ch); curl_close($ch); fclose($fh); } $ time \php cURL.php real 0m0.114s user 0m0.032s sys 0m0.052s
pecl_http(pecl installでウィザードは全部Enter)
$ cat pecl_http.php <?php for ($i=1; $i <=100; $i++) { http_get('http://localhost/favicon.ico'); } $ time \php pecl_http.php real 0m0.091s user 0m0.040s sys 0m0.032s
pecl_http(その2)
$ cat pecl_http_class.php <?php for ($i=1; $i <=100; $i++) { $r = new HttpRequest('http://localhost/favicon.ico', HttpRequest::METH_GET); $r->send(); } $ time \php pecl_http_class.php real 0m0.093s user 0m0.036s sys 0m0.040s
pecl_http(pool版 1回めと2回め以降で全然違う。。。)
$ cat pecl_http_pool.php <?php $pool = new HttpRequestPool; for ($i=1; $i <=100; $i++) { $pool->attach(new HttpRequest('http://localhost/favicon.ico')); } $pool->send(); $ time \php pecl_http_pool.php real 0m6.796s user 0m0.664s sys 0m1.580s $ time \php pecl_http_pool.php real 0m0.124s user 0m0.056s sys 0m0.044s
lithium0.9.5
$ cat lithium-095.php <?php require_once 'SplClassLoader.php'; $loader = new SplClassLoader(); $loader->setIncludePath(__DIR__ . '/libraries'); $loader->register(); for ($i=1;$i<=100;$i++) { $http = new lithium\net\http\Service(array('host' => 'localhost')); $r = $http->get('/favicon.ico'); } $ time \php lithium-095.php real 0m0.178s user 0m0.108s sys 0m0.040s
ただのsocket_clientだとかsfWebBrowserとかHordeだとかは誰かやってください。
参照:
LLごとの標準的なHTTPクライアントで100リクエスト投げた時のベンチマーク
http://subtech.g.hatena.ne.jp/mala/20100531/1275322139
ついき:ちなみに「そんなリクエストごとにクライアントオブジェクト生成しないわー」と思って、下のもやってみましたが、あんまりかわりませんでした。あれ。
<?php require_once 'Zend/Http/Client.php'; $client = new Zend_Http_Client(); for ($i=1; $i <=100; $i++) { $client->setUri('http://localhost/favicon.ico'); $client->request(); }