{"id":1316,"date":"2018-01-19T19:22:42","date_gmt":"2018-01-19T19:22:42","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/php-multithreading-with-curl-page-2\/"},"modified":"2018-01-19T19:24:41","modified_gmt":"2018-01-19T19:24:41","slug":"php-multithreading-with-curl-page-2","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/php-multithreading-with-curl-page-2\/","title":{"rendered":"PHP Multithreading with cURL Page 2"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By Octavia Andreea Anghel<\/div>\n<div class=\"\">on June 14, 2011<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\">\n<div class=\"articlePara\">\nAs you can see from the Figure 2 on the previous page, the <code>curl_getinfo($curl)<\/code> method lists some curl info, like the url, connect_time and so on:\n<\/div>\n<pre>\nArray\n(\n[url] =&gt; http:\/\/www.google.ro\n[content_type] =&gt; text\/html; charset=ISO-8859-2\n[http_code] =&gt; 200\n[header_size] =&gt; 604\n[request_size] =&gt; 52\n[filetime] =&gt; -1\n[ssl_verify_result] =&gt; 0\n[redirect_count] =&gt; 0\n[total_time] =&gt; 1.125\n[namelookup_time] =&gt; 0.265\n[connect_time] =&gt; 0.5\n[pretransfer_time] =&gt; 0.5\n[size_upload] =&gt; 0\n[size_download] =&gt; 27552\n[speed_download] =&gt; 24490\n[speed_upload] =&gt; 0\n[download_content_length] =&gt; -1\n[upload_content_length] =&gt; 0\n[starttransfer_time] =&gt; 0.734\n[redirect_time] =&gt; 0\n[certinfo] =&gt; Array\n(\n)\n\n)\n<\/pre>\n<div class=\"articlePara\">\nThe example below simulates the multithreading mechanism by initializating a new session and returns a cURL handle, sets the options for the <em>http:\/\/www.google.ro<\/em> and <em>http:\/\/ro.yahoo.com\/?p=us<\/em> URLs, executes the cURL session and then prints the results using the <code>curl_getinfo<\/code> method:\n<\/div>\n<pre>\n&lt;:!--?php\n\n\/\/ Creating an array of URLs that will be used below\n$urls_array = array('http:\/\/www.google.ro',' http:\/\/ro.yahoo.com\/?p=us');\n\n$curl_array = array();\n\n\/\/ Initializes a new session and return a cURL multi handle for use with the <br\/>curl_setopt(), curl_exec() and curl_close() functions\n$curl_multi_handle = curl_multi_init();\n\n\/\/ Use the urls_array array for initialize a single session, set the transfer <br\/>and to add a normal cURL handle to a cURL multi handle\nfor($i = 0; $i  0) ;\n\necho \"results: \";\n\nfor($i = 0; $i \n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/phpbuilder.com\/wp-content\/uploads\/2018\/01\/Figure3.jpg\" width=\"600\" height=\"600\"\/><\/p>\n<div class=\"articlePara\">\n<strong>Figure 3<\/strong>: The above application simulates the cURL mechanism using some control structures and some of the most important cURL methods like <code>curl_setopt<\/code>, <code>curl_multi_exec<\/code> and <code>curl_multi_getcontent<\/code>.\n<\/div>\n<h2>Conclusion<\/h2>\n<div class=\"articlePara\">\nIn this article you have seen how to make the libcurl library functional in PHP, how to executes cURL sessions, how to print curl info like HTTP response code and content type, and how to simulates the cURL mechanism.\n<\/div>\n<h2>About the Author<\/h2>\n<div class=\"articlePara\"><em><strong>Octavia Andreea Anghel<\/strong> is a senior PHP developer currently working as a primary trainer for programming teams that participate at national and international software-development contests. She consults on developing educational projects at a national level. She is a coauthor of the book &#8220;XML Technologies: XML in Java&#8221; (Albastra, ISBN 978-973-650-210-1), for which she wrote the XML portions. In addition to PHP and XML, she&#8217;s interested in software architecture, web services, UML, and high-performance unit tests.  to e-mail her.<\/em><\/div>\n<\/div>\n<p><\/p>\n<div style=\"float: left; padding:15px; color:#17AAF3\">\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"Octavia_Anghel06072011.html\">\u00ab Previous Page<\/a><\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"Octavia_Anghel06072011.html\">1<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"background-color:#B6E5FC; font-size:16px; margin-top:1px; padding:1px 4px 1px 4px; color:#000; font-style:bold; float:left;\">2<\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>When there are many tasks to execute in a given script, it may take a long time to finish all of them if they are executed sequentially, i.e., one<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1316","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1316","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=1316"}],"version-history":[{"count":1,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1316\/revisions"}],"predecessor-version":[{"id":2161,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1316\/revisions\/2161"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=1316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=1316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=1316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}