<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Get information regarding a specific transfer</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.curl-file-create.html">curl_file_create</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.curl-init.html">curl_init</a></div> <div class="up"><a href="ref.curl.html">cURL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.curl-getinfo" class="refentry"> <div class="refnamediv"> <h1 class="refname">curl_getinfo</h1> <p class="verinfo">(PHP 4 >= 4.0.4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">curl_getinfo</span> — <span class="dc-title">Get information regarding a specific transfer</span></p> </div> <div class="refsect1 description" id="refsect1-function.curl-getinfo-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>curl_getinfo</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$ch</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$opt</code></span> ] )</div> <p class="para rdfs-comment"> Gets information about the last transfer. </p> </div> <div class="refsect1 parameters" id="refsect1-function.curl-getinfo-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">ch</code> </dt> <dd> <p class="para">A cURL handle returned by <span class="function"><a href="function.curl-init.html" class="function">curl_init()</a></span>.</p></dd> <dt> <code class="parameter">opt</code></dt> <dd> <p class="para"> This may be one of the following constants: <ul class="itemizedlist"> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_EFFECTIVE_URL</code></strong> - Last effective URL </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_HTTP_CODE</code></strong> - The last response code. As of PHP 5.5.0 and cURL 7.10.8, this is a legacy alias of <strong><code>CURLINFO_RESPONSE_CODE</code></strong> </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_FILETIME</code></strong> - Remote time of the retrieved document, with the <strong><code>CURLOPT_FILETIME</code></strong> enabled; if -1 is returned the time of the document is unknown </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_TOTAL_TIME</code></strong> - Total transaction time in seconds for last transfer </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_NAMELOOKUP_TIME</code></strong> - Time in seconds until name resolving was complete </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_CONNECT_TIME</code></strong> - Time in seconds it took to establish the connection </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_PRETRANSFER_TIME</code></strong> - Time in seconds from start until just before file transfer begins </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_STARTTRANSFER_TIME</code></strong> - Time in seconds until the first byte is about to be transferred </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_REDIRECT_COUNT</code></strong> - Number of redirects, with the <strong><code>CURLOPT_FOLLOWLOCATION</code></strong> option enabled </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_REDIRECT_TIME</code></strong> - Time in seconds of all redirection steps before final transaction was started, with the <strong><code>CURLOPT_FOLLOWLOCATION</code></strong> option enabled </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_REDIRECT_URL</code></strong> - With the <strong><code>CURLOPT_FOLLOWLOCATION</code></strong> option disabled: redirect URL found in the last transaction, that should be requested manually next. With the <strong><code>CURLOPT_FOLLOWLOCATION</code></strong> option enabled: this is empty. The redirect URL in this case is available in <strong><code>CURLINFO_EFFECTIVE_URL</code></strong> </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_PRIMARY_IP</code></strong> - IP address of the most recent connection </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_PRIMARY_PORT</code></strong> - Destination port of the most recent connection </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_LOCAL_IP</code></strong> - Local (source) IP address of the most recent connection </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_LOCAL_PORT</code></strong> - Local (source) port of the most recent connection </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_SIZE_UPLOAD</code></strong> - Total number of bytes uploaded </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_SIZE_DOWNLOAD</code></strong> - Total number of bytes downloaded </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_SPEED_DOWNLOAD</code></strong> - Average download speed </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_SPEED_UPLOAD</code></strong> - Average upload speed </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_HEADER_SIZE</code></strong> - Total size of all headers received </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_HEADER_OUT</code></strong> - The request string sent. For this to work, add the <strong><code>CURLINFO_HEADER_OUT</code></strong> option to the handle by calling <span class="function"><a href="function.curl-setopt.html" class="function">curl_setopt()</a></span> </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_REQUEST_SIZE</code></strong> - Total size of issued requests, currently only for HTTP requests </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_SSL_VERIFYRESULT</code></strong> - Result of SSL certification verification requested by setting <strong><code>CURLOPT_SSL_VERIFYPEER</code></strong> </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_CONTENT_LENGTH_DOWNLOAD</code></strong> - Content length of download, read from <em>Content-Length:</em> field </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_CONTENT_LENGTH_UPLOAD</code></strong> - Specified size of upload </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_CONTENT_TYPE</code></strong> - <em>Content-Type:</em> of the requested document. NULL indicates server did not send valid <em>Content-Type:</em> header </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_PRIVATE</code></strong> - Private data associated with this cURL handle, previously set with the <strong><code>CURLOPT_PRIVATE</code></strong> option of <span class="function"><a href="function.curl-setopt.html" class="function">curl_setopt()</a></span> </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_RESPONSE_CODE</code></strong> - The last response code </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_HTTP_CONNECTCODE</code></strong> - The CONNECT response code </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_HTTPAUTH_AVAIL</code></strong> - Bitmask indicating the authentication method(s) available according to the previous response </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_PROXYAUTH_AVAIL</code></strong> - Bitmask indicating the proxy authentication method(s) available according to the previous response </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_OS_ERRNO</code></strong> - Errno from a connect failure. The number is OS and system specific. </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_NUM_CONNECTS</code></strong> - Number of connections curl had to create to achieve the previous transfer </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_SSL_ENGINES</code></strong> - OpenSSL crypto-engines supported </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_COOKIELIST</code></strong> - All known cookies </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_FTP_ENTRY_PATH</code></strong> - Entry path in FTP server </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_APPCONNECT_TIME</code></strong> - Time in seconds it took from the start until the SSL/SSH connect/handshake to the remote host was completed </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_CERTINFO</code></strong> - TLS certificate chain </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_CONDITION_UNMET</code></strong> - Info on unmet time conditional </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_RTSP_CLIENT_CSEQ</code></strong> - Next RTSP client CSeq </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_RTSP_CSEQ_RECV</code></strong> - Recently received CSeq </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_RTSP_SERVER_CSEQ</code></strong> - Next RTSP server CSeq </span> </li> <li class="listitem"> <span class="simpara"> <strong><code>CURLINFO_RTSP_SESSION_ID</code></strong> - RTSP session ID </span> </li> </ul> </p> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.curl-getinfo-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> If <code class="parameter">opt</code> is given, returns its value. Otherwise, returns an associative array with the following elements (which correspond to <code class="parameter">opt</code>), or <strong><code>FALSE</code></strong> on failure: <ul class="itemizedlist"> <li class="listitem"> <span class="simpara"> "url" </span> </li> <li class="listitem"> <span class="simpara"> "content_type" </span> </li> <li class="listitem"> <span class="simpara"> "http_code" </span> </li> <li class="listitem"> <span class="simpara"> "header_size" </span> </li> <li class="listitem"> <span class="simpara"> "request_size" </span> </li> <li class="listitem"> <span class="simpara"> "filetime" </span> </li> <li class="listitem"> <span class="simpara"> "ssl_verify_result" </span> </li> <li class="listitem"> <span class="simpara"> "redirect_count" </span> </li> <li class="listitem"> <span class="simpara"> "total_time" </span> </li> <li class="listitem"> <span class="simpara"> "namelookup_time" </span> </li> <li class="listitem"> <span class="simpara"> "connect_time" </span> </li> <li class="listitem"> <span class="simpara"> "pretransfer_time" </span> </li> <li class="listitem"> <span class="simpara"> "size_upload" </span> </li> <li class="listitem"> <span class="simpara"> "size_download" </span> </li> <li class="listitem"> <span class="simpara"> "speed_download" </span> </li> <li class="listitem"> <span class="simpara"> "speed_upload" </span> </li> <li class="listitem"> <span class="simpara"> "download_content_length" </span> </li> <li class="listitem"> <span class="simpara"> "upload_content_length" </span> </li> <li class="listitem"> <span class="simpara"> "starttransfer_time" </span> </li> <li class="listitem"> <span class="simpara"> "redirect_time" </span> </li> <li class="listitem"> <span class="simpara"> "certinfo" </span> </li> <li class="listitem"> <span class="simpara"> "primary_ip" </span> </li> <li class="listitem"> <span class="simpara"> "primary_port" </span> </li> <li class="listitem"> <span class="simpara"> "local_ip" </span> </li> <li class="listitem"> <span class="simpara"> "local_port" </span> </li> <li class="listitem"> <span class="simpara"> "redirect_url" </span> </li> <li class="listitem"> <span class="simpara"> "request_header" (This is only set if the <strong><code>CURLINFO_HEADER_OUT</code></strong> is set by a previous call to <span class="function"><a href="function.curl-setopt.html" class="function">curl_setopt()</a></span>) </span> </li> </ul> Note that private data is not included in the associative array and must be retrieved individually with the <strong><code>CURLINFO_PRIVATE</code></strong> option. </p> </div> <div class="refsect1 changelog" id="refsect1-function.curl-getinfo-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.5.0</td> <td> Introduced <strong><code>CURLINFO_RESPONSE_CODE</code></strong>, <strong><code>CURLINFO_HTTP_CONNECTCODE</code></strong>, <strong><code>CURLINFO_HTTPAUTH_AVAIL</code></strong>, <strong><code>CURLINFO_PROXYAUTH_AVAIL</code></strong>, <strong><code>CURLINFO_OS_ERRNO</code></strong>, <strong><code>CURLINFO_NUM_CONNECTS</code></strong>, <strong><code>CURLINFO_SSL_ENGINES</code></strong>, <strong><code>CURLINFO_COOKIELIST</code></strong>, <strong><code>CURLINFO_FTP_ENTRY_PATH</code></strong>, <strong><code>CURLINFO_APPCONNECT_TIME</code></strong>, <strong><code>CURLINFO_CONDITION_UNMET</code></strong>, <strong><code>CURLINFO_RTSP_CLIENT_CSEQ</code></strong>, <strong><code>CURLINFO_RTSP_CSEQ_RECV</code></strong>, <strong><code>CURLINFO_RTSP_SERVER_CSEQ</code></strong> and <strong><code>CURLINFO_RTSP_SESSION_ID</code></strong>. </td> </tr> <tr> <td>5.4.7</td> <td> Introduced <strong><code>CURLINFO_PRIMARY_IP</code></strong>, <strong><code>CURLINFO_PRIMARY_PORT</code></strong>, <strong><code>CURLINFO_LOCAL_IP</code></strong> and <strong><code>CURLINFO_LOCAL_PORT</code></strong>. </td> </tr> <tr> <td>5.3.7</td> <td> Introduced <strong><code>CURLINFO_REDIRECT_URL</code></strong>. </td> </tr> <tr> <td>5.3.0</td> <td> Introduced <strong><code>CURLINFO_CERTINFO</code></strong>. </td> </tr> <tr> <td>5.2.4</td> <td> Introduced <strong><code>CURLINFO_PRIVATE</code></strong>. </td> </tr> <tr> <td>5.1.3</td> <td> Introduced <strong><code>CURLINFO_HEADER_OUT</code></strong>. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.curl-getinfo-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-5372"> <p><strong>Example #1 <span class="function"><strong>curl_getinfo()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Create a cURL handle<br /></span><span style="color: #0000BB">$ch </span><span style="color: #007700">= </span><span style="color: #0000BB">curl_init</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com/'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Execute<br /></span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Check if any error occurred<br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">curl_errno</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">$info </span><span style="color: #007700">= </span><span style="color: #0000BB">curl_getinfo</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /> echo </span><span style="color: #DD0000">'Took '</span><span style="color: #007700">, </span><span style="color: #0000BB">$info</span><span style="color: #007700">[</span><span style="color: #DD0000">'total_time'</span><span style="color: #007700">], </span><span style="color: #DD0000">' seconds to send a request to '</span><span style="color: #007700">, </span><span style="color: #0000BB">$info</span><span style="color: #007700">[</span><span style="color: #DD0000">'url'</span><span style="color: #007700">], </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// Close handle<br /></span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para"> <div class="example" id="example-5373"> <p><strong>Example #2 <span class="function"><strong>curl_getinfo()</strong></span> example with <code class="parameter">opt</code> parameter</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// Create a cURL handle<br /></span><span style="color: #0000BB">$ch </span><span style="color: #007700">= </span><span style="color: #0000BB">curl_init</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com/'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Execute<br /></span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Check HTTP status code<br /></span><span style="color: #007700">if (!</span><span style="color: #0000BB">curl_errno</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">)) {<br /> switch (</span><span style="color: #0000BB">$http_code </span><span style="color: #007700">= </span><span style="color: #0000BB">curl_getinfo</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">, </span><span style="color: #0000BB">CURLINFO_HTTP_CODE</span><span style="color: #007700">)) {<br /> case </span><span style="color: #0000BB">200</span><span style="color: #007700">: </span><span style="color: #FF8000"># OK<br /> </span><span style="color: #007700">break;<br /> default:<br /> echo </span><span style="color: #DD0000">'Unexpected HTTP code: '</span><span style="color: #007700">, </span><span style="color: #0000BB">$http_code</span><span style="color: #007700">, </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /> }<br />}<br /><br /></span><span style="color: #FF8000">// Close handle<br /></span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.curl-getinfo-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Information gathered by this function is kept if the handle is re-used. This means that unless a statistic is overridden internally by this function, the previous info is returned. </p> </p></blockquote> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.curl-file-create.html">curl_file_create</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.curl-init.html">curl_init</a></div> <div class="up"><a href="ref.curl.html">cURL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>