{"id":166633,"date":"2013-01-22T15:16:03","date_gmt":"2013-01-22T11:16:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=166633"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=166633","title":{"rendered":"<span class=\"post_title\">\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438: curl, php curl, php socket, python pycurl<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041c\u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0435\u043a\u0442, \u043c\u043e\u0434\u0443\u043b\u044c \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044f \u0435\u043c\u0443 GET \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<br \/>  \u042f \u043f\u0440\u043e\u0432\u0435\u043b \u0442\u0435\u0441\u0442\u044b \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0431\u0443\u0434\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 (\u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0430).<\/p>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0435 3 \u0442\u0435\u0441\u0442\u0430: \u043a\u0430\u0436\u0434\u044b\u043c \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u043e\u0441\u044c \u043f\u043e 50 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e\u0434\u0440\u044f\u0434 \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u0430\u0439\u0442\u0443. <\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/phpdreamer.ru\/images\/habrapost\/table1.png\" alt=\"image\"\/><br \/>  <a name=\"habracut\"><\/a><br \/>  <img decoding=\"async\" src=\"http:\/\/phpdreamer.ru\/images\/habrapost\/image001.png\" alt=\"image\"\/><br \/>  \u041f\u043e\u044f\u0441\u043d\u044e, \u0447\u0442\u043e curl \u2014 \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u043e\u0439 \u0443\u0442\u0438\u043b\u0438\u0442\u043e\u0439 curl \u0432 Linux. \u0412\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u0432 Linux.<br \/>  \u0422\u0430\u043a\u0436\u0435 \u0431\u044b\u043b \u043f\u044f\u0442\u044b\u0439 \u0442\u0435\u0441\u0442 \u2014 \u0432\u044b\u0437\u043e\u0432 curl \u0438\u0437 php \u0447\u0435\u0440\u0435\u0437 exec, \u043d\u043e \u044d\u0442\u0443 \u0433\u043b\u0443\u043f\u043e\u0441\u0442\u044c \u044f \u043e\u0442\u0431\u0440\u043e\u0441\u0438\u043b. <\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0443\u0441\u0440\u0435\u0434\u043d\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u044b, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<br \/>  <img decoding=\"async\" src=\"http:\/\/phpdreamer.ru\/images\/habrapost\/image008.png\" alt=\"image\"\/><\/p>\n<p>  \u041c\u0435\u0441\u0442\u0430:   <\/p>\n<ol>\n<li> php socket<\/li>\n<li> curl<\/li>\n<li> python pycurl<\/li>\n<li> php curl<\/li>\n<\/ol>\n<p>  \u0415\u0441\u043b\u0438 \u043e\u0442\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0438\u0436\u043d\u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f:<br \/>  <img decoding=\"async\" src=\"http:\/\/phpdreamer.ru\/images\/habrapost\/image010.png\" alt=\"image\"\/><\/p>\n<ol>\n<li> php socket<\/li>\n<li> php curl<\/li>\n<li> python pycurl<\/li>\n<li> curl<\/li>\n<\/ol>\n<p>  \u041a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u044b\u0439 curl \u0431\u0435\u0437 \u042f\u041f \u043c\u0435\u043d\u044f \u0443\u0436\u0435 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u0442\u0430\u043a\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432, \u043d\u043e \u043a\u0442\u043e \u0436\u0435 \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 php+curl \u0438\u043b\u0438 python+pycurl? \u0415\u0449\u0435 4 \u0442\u0435\u0441\u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u0430 \u043f\u0430\u0440\u0430:<br \/>  <img decoding=\"async\" src=\"http:\/\/phpdreamer.ru\/images\/habrapost\/t2.png\" alt=\"image\"\/><\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/phpdreamer.ru\/images\/habrapost\/image012.png\" alt=\"image\"\/><br \/>  php \u0447\u0435\u0441\u0442\u043d\u043e \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0432\u043e \u0432\u0441\u0435\u0445 4 \u0442\u0435\u0441\u0442\u0430\u0445.<\/p>\n<h3>\u0418\u0442\u043e\u0433\u0438 \u0442\u0435\u0441\u0442\u043e\u0432<\/h3>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 curl \u043f\u0440\u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 GET \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 <br \/>   \u2014 \u044d\u0442\u043e \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u0435 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0447\u0442\u0438 \u0432 2 \u0440\u0430\u0437\u0430 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0440\u0430\u0431\u043e\u0442\u043e\u0439 \u0447\u0435\u0440\u0435\u0437 \u0441\u043e\u043a\u0435\u0442\u044b. <br \/>  \u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0447\u0442\u043e \u043f\u0438\u0442\u043e\u043d \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 pycurl \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c php \u0441 curl. <br \/>  \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0442\u0435\u0441\u0442\u044b \u0432 \u0447\u0435\u043c \u0442\u043e \u043d\u0435\u043e\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u044b, \u0435\u0441\u043b\u0438 \u0412\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a, \u043e\u0431\u043e\u0441\u043d\u0443\u0439\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. <\/p>\n<h3>\u041a\u043e\u0434 \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432<\/h3>\n<p>  <\/p>\n<h5>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0430 C<\/h5>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u0443\u044e \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 \u0438 \u0437\u0430\u043c\u0435\u0440\u044f\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0435\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445.  <\/p>\n<pre><code>#include &lt;sys\/time.h&gt; #include &lt;stdlib.h&gt;  struct timeval tv1, tv2, dtv; struct timezone tz;  \/\/time_ functions from http:\/\/ccfit.nsu.ru\/~kireev\/lab1\/lab1time.htm void time_start()  {  \tgettimeofday(&tv1, &tz);  } long time_stop() { \tgettimeofday(&tv2, &tz); \tdtv.tv_sec= tv2.tv_sec -tv1.tv_sec; \tdtv.tv_usec=tv2.tv_usec-tv1.tv_usec;  \tif(dtv.tv_usec &lt; 0)  \t{  \t\tdtv.tv_sec--;  \t\tdtv.tv_usec += 1000000;  \t}      return dtv.tv_sec * 1000 + dtv.tv_usec \/ 1000; }  int main(int argc, char **argv) {\t \tif(argc &gt; 1) \t{ \t\ttime_start(); \t\tsystem(argv[1]); \t\tprintf(&quot;\\nTime: %ld\\n&quot;, time_stop()); \t} \telse \t\tprintf(&quot;Usage:\\n timer1 command\\n&quot;);\t \t \treturn 0; } <\/code><\/pre>\n<h5>PHP<\/h5>\n<p>  <\/p>\n<pre><code class=\"php\">$t = 'http:\/\/www.2ip.ru\/'; \/\/target  for($i=0; $i &lt; 50; $i++) { \t$ch = curl_init(); \tcurl_setopt($ch, CURLOPT_URL, $t); \tcurl_setopt($ch, CURLOPT_HEADER, 1); \tcurl_setopt($ch, CURLINFO_HEADER_OUT, 1); \tcurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); \tcurl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla\/5.0 (X11; Linux x86_64; rv:17.0) Gecko\/17.0 Firefox\/17.0'); \tcurl_setopt($ch, CURLOPT_ENCODING, 'utf-8'); \tcurl_setopt($ch, CURLOPT_TIMEOUT, 200); \tcurl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); \tcurl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); \t$data = curl_exec($ch);         \tcurl_close($ch); } <\/code><\/pre>\n<p>  \u0421\u0430\u043c\u044b\u0439 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 (\u0441\u043e\u043a\u0435\u0442\u044b)  <\/p>\n<pre><code class=\"php\">$t = 'http:\/\/www.2ip.ru\/'; \/\/target  for($i=0; $i &lt; 50; $i++) { \t$service_port = 80; \t$address = gethostbyname('www.2ip.ru'); \t$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); \tif ($socket === false) { \t\techo &quot;socket_create() failed: reason: &quot; . socket_strerror(socket_last_error()) . &quot;\\n&quot;; \t} else { \t\t\/\/echo &quot;OK.\\n&quot;; \t}  \t$result = socket_connect($socket, $address, $service_port); \tif ($result === false) { \t\techo &quot;socket_connect() failed.\\nReason: ($result) &quot; . socket_strerror(socket_last_error($socket)) . &quot;\\n&quot;; \t} else { \t\t\/\/echo &quot;OK.\\n&quot;; \t} \t$in = &quot;GET \/ HTTP\/1.1\\r\\n&quot;; \t$in .= &quot;Host: www.example.com\\r\\n&quot;; \t$in .= &quot;Connection: Close\\r\\n\\r\\n&quot;; \t$out = ''; \t$r = ''; \tsocket_write($socket, $in, strlen($in)); \t \twhile ($out = socket_read($socket, 2048)) { \t\t$r .= $out; \t} \tsocket_close($socket); \t\/\/echo $r; } <\/code><\/pre>\n<h5>Python<\/h5>\n<p>  <\/p>\n<pre><code class=\"python\">import pycurl import cStringIO   for i in range(50): \tbuf = cStringIO.StringIO() \tc = pycurl.Curl() \tc.setopt(c.URL, 'http:\/\/www.2ip.ru\/') \tc.setopt(c.WRITEFUNCTION, buf.write) \tc.perform() \t#print buf.getvalue() \tbuf.close() <\/code><\/pre>\n<h5>\u0421\u043a\u0440\u0438\u043f\u0442\u044b bash<\/h5>\n<p>  \u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 curl:  <\/p>\n<pre><code class=\"bash\">#!\/bin\/bash testdir=&quot;\/home\/developer\/Desktop\/tests&quot; i=0 while [ $i -lt 50 ] do   curl -s -o &quot;$testdir\/tmp_some_file&quot; &quot;http:\/\/www.2ip.ru\/&quot;   let i=i+1 done <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u0441\u0435\u0445 \u0442\u0435\u0441\u0442\u043e\u0432:  <\/p>\n<pre><code class=\"bash\">#!\/bin\/bash  testdir=&quot;\/home\/developer\/Desktop\/tests&quot; echo &quot;php curl&quot; &quot;$testdir\/timer1&quot; &quot;php $testdir\/testCurl.php&quot;  echo &quot;curl to file&quot; &quot;$testdir\/timer1&quot; &quot;bash $testdir\/curl2file.sh&quot;  #echo &quot;curl to file (php)&quot; #&quot;$testdir\/timer1&quot; &quot;php $testdir\/testCurl2.php&quot;  echo &quot;php socket&quot; &quot;$testdir\/timer1&quot; &quot;php $testdir\/testCurl3.php&quot;  echo &quot;python pycurl&quot; &quot;$testdir\/timer1&quot; &quot;python $testdir\/1.py&quot; <\/code><\/pre>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/166633\/\"> http:\/\/habrahabr.ru\/post\/166633\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041c\u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0435\u043a\u0442, \u043c\u043e\u0434\u0443\u043b\u044c \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044f \u0435\u043c\u0443 GET \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<br \/>  \u042f \u043f\u0440\u043e\u0432\u0435\u043b \u0442\u0435\u0441\u0442\u044b \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0431\u0443\u0434\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 (\u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0430).<\/p>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0435 3 \u0442\u0435\u0441\u0442\u0430: \u043a\u0430\u0436\u0434\u044b\u043c \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u043e\u0441\u044c \u043f\u043e 50 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e\u0434\u0440\u044f\u0434 \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u0430\u0439\u0442\u0443. <\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/phpdreamer.ru\/images\/habrapost\/table1.png\" alt=\"image\"\/>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-166633","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/166633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=166633"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/166633\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=166633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=166633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=166633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}