- <?php
- function test_it($uri)
- {
- //$handle = curl_init($uri);
- $handle = curl_init();
- curl_setopt( $handle, CURLOPT_URL, $uri);
- $theHeaders = '';
- #
- # The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
- # {in WP $timeout }
- curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 5000);
- #
- # The maximum number of seconds to allow cURL functions to execute.
- # {in WP treated as the same as $timeout }
- curl_setopt( $handle, CURLOPT_TIMEOUT, 5000);
- #
- # The number of milliseconds to wait while trying to connect. Use 0 to wait indefinitely.
- # If libcurl is built to use the standard system name resolver, that portion of the connect
- # will still use full-second resolution for timeouts with a minimum timeout allowed of one second.
- # {can not be set in WP}
- //curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT_MS, 5000);
- #
- # The number of seconds to keep DNS entries in memory. This option is set to 120 (2 minutes) by default.
- # {can not be set in WP}
- //curl_setopt( $handle, CURLOPT_DNS_CACHE_TIMEOUT );
- # The contents of the "Accept-Encoding: " header. This enables decoding of the response.
- # Supported encodings are "identity", "deflate", and "gzip". If an empty string, "", is set,
- # a header containing all supported encoding types is sent.
- #
- //curl_setopt( $handle, CURLOPT_ENCODING, '');
- //curl_setopt( $handle, CURLOPT_TRANSFERTEXT, false);
- //curl_setopt( $handle, CURLOPT_BINARYTRANSFER, false);
- # TRUE to be completely silent with regards to the cURL functions.
- //curl_setopt( $handle, CURLOPT_MUTE, false);
- //curl_setopt( $handle, CURLOPT_VERBOSE, false);
- #
- # 1 to check the existence of a common name in the SSL peer certificate. 2 to check the existence of
- # a common name and also verify that it matches the hostname provided.
- # {in WP $ssl_verify} {i assume false will be 0 and true will be treated as ?}
- curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, 1 );
- #
- # FALSE to stop cURL from verifying the peer's certificate. Alternate certificates to verify against can
- # be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the
- # CURLOPT_CAPATH option. CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if CURLOPT_SSL_VERIFYPEER
- # is disabled (it defaults to 2).
- # {in WP also $ss_verify}
- curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, false );
- #
- # Autoreferr set by Curl
- # {in WP not used as they have their own default string}
- //curl_setopt( $handle, CURLOPT_AUTOREFERER, false);
- #
- # The contents of the "User-Agent: " header to be used in a HTTP request.
- # {in WP user-agent filter or parameter}
- curl_setopt( $handle, CURLOPT_USERAGENT, 'WP-Favicon/0.5.1 (http://wordpress.org/extend/plugins/wp-favicons/; http://www.favcollector.com/)');
- #
- # The contents of the "Referer: " header to be used in a HTTP request.
- # {not set in WP}
- //curl_setopt( $handle, CURLOPT_REFERER, '');
- # Bitmask of CURLPROTO_* values. If used, this bitmask limits what protocols libcurl may use in a transfer
- # that it follows to in a redirect when CURLOPT_FOLLOWLOCATION is enabled. This allows you to limit specific
- # transfers to only be allowed to use a subset of protocols in redirections. By default libcurl will allow all
- # protocols except for FILE and SCP. This is a difference compared to pre-7.19.4 versions which unconditionally
- # would follow to all protocols supported. See also CURLOPT_PROTOCOLS for protocol constant values.
- # {not used in WP though would be handy to exclude protocols for favicons}
- //curl_setopt( $handle, CURLOPT_REDIR_PROTOCOLS, '')
- #
- # The maximum amount of HTTP redirections to follow. Use this option alongside CURLOPT_FOLLOWLOCATION.
- # { in WP redirection filter or parameter by default 5}
- curl_setopt( $handle, CURLOPT_MAXREDIRS, 0 );
- #
- # TRUE to follow any "Location: " header that the server sends as part of the HTTP header
- # (note this is recursive, PHP will follow as many "Location: " headers that it is sent,
- # unless CURLOPT_MAXREDIRS is set).
- # { in WP not yet: see: https://core.trac.wordpress.org/ticket/16855#comment:19}
- # { in our case set this to false if redirection is set to 0 }
- curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, false );
- #
- # TRUE to fail silently if the HTTP code returned is greater than or equal to 400. The
- # default behavior is to return the page normally, ignoring the code.
- # {not set in WP, it will handle errors itself in class-http.php lines 1410+}
- //curl_setopt( $handle, CURLOPT_FAILONERROR, false);
- #
- # TRUE to exclude the body from the output. Request method is then set to HEAD.
- # Changing this to FALSE does not change it to GET.
- # {set in WP when called by wp_remote_head or with a parameter 'HEAD' then this is set to false}
- curl_setopt( $handle, CURLOPT_NOBODY, false );
- #
- # TRUE to include the header in the output. (wp's blocking versus non blocking)
- # {in WP this is true when the 'blocking' parameter is set, which is the default}
- //curl_setopt( $handle, CURLOPT_HEADER, true);
- #
- # TRUE to track the handle's request string.
- # {not set in WP though handy for debugging favicon code}
- //curl_setopt( $handle, CURLINFO_HEADER_OUT, true);
- #
- # An array of HTTP header fields to set, in the format array('Content-type: text/plain', 'Content-length: 100')
- # To reset it it needs to be set to array
- # {in WP set as headers array parameter}
- //curl_setopt( $handle, CURLOPT_HTTPHEADER, array());
- #
- # CURL_HTTP_VERSION_NONE (default, lets CURL decide which version to use),
- # CURL_HTTP_VERSION_1_0 (forces HTTP/1.0), or CURL_HTTP_VERSION_1_1 (forces HTTP/1.1).
- # { in WP default set to 1.0 }
- // curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE );
- curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
- #
- # TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
- # FALSE output it directly
- # {in WP always true to parse it in fixed HTTP API format}
- curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true );
- $theResponse = curl_exec( $handle );
- if ( !empty($theResponse) ) {
- echo 'there was a response' . "<br />";
- $headerLength = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
- $theHeaders = trim( substr($theResponse, 0, $headerLength) );
- if ( strlen($theResponse) > $headerLength )
- $theBody = substr( $theResponse, $headerLength );
- else
- $theBody = '';
- if ( false !== strpos($theHeaders, "\r\n\r\n") ) {
- $headerParts = explode("\r\n\r\n", $theHeaders);
- $theHeaders = $headerParts[ count($headerParts) -1 ];
- }
- } else {
- echo 'there was no response <br />';
- if ( $curl_error = curl_error($handle) )
- echo $curl_error . "<br />";
- if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array(301, 302) ) )
- echo 'Too many redirects.' . "<br >" ;
- $theHeaders = array( 'headers' => array(), 'cookies' => array() );
- $theBody = '';
- }
- echo $theHeaders;
- echo $theBody;
- echo curl_getinfo( $handle, CURLINFO_HTTP_CODE );
- }
- test_it('http://www.informationweek.com/story/');
SHARE
TWEET

Untitled




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.