the callback function to be executed for each and every
request, as soon as a request finishes
the callback function receives as argument an object with 4 properties
(info, header, body and response)
function mycallback($result) {
everything went well at cURL level
if ($result->response[1] == CURLE_OK) {
if server responded with code 200 (meaning that everything went well)
see http://httpstatus.es/ for a list of possible response codes
if ($result->info['http_code'] == 200) {
see all the returned data
print_r('
');
print_r($result);
show the server's response code
} else die('Server responded with code ' . $result->info['http_code']);
something went wrong
($result still contains all data that could be gathered)
} else die('cURL responded with: ' . $result->response[0]);
}
include the Zebra_cURL library
require 'path/to/Zebra_cURL';
instantiate the Zebra_cURL object
$curl = new Zebra_cURL();
process given URLs execute the "mycallback" function for each
request, as soon as it finishes
$curl->header('http://www.somewebsite.com', 'mycallback');
public header ( mixed $urls, mixed $callback = '' ) : void | ||
$urls | mixed | A single URL or an array of URLs to process. @param mixed $callback (Optional) Callback function to be called as soon as a request finishes. May be given as a string representing a name of an existing function, as an anonymous function created on the fly via {@link http://www.php.net/manual/en/function.create-function.php create_function} or via a {@link http://www.php.net/manual/en/function.create-function.php closure}. The callback function receives as first argument an object with 4 properties as described below, while any further arguments passed to the {@link header} method will be passed as extra arguments to the callback function: - info - an associative array containing information about the request that just finished, as returned by PHP's {@link http://php.net/manual/en/function.curl-getinfo.php curl_getinfo} function; - headers - an associative array with 2 items: - last_request an array with a single entry containing the request headers generated by the last request; so, remember, if there are redirects involved, there will be more requests made, but only information from the last one will be available; - responses an array with one or more entries (if there are redirects involved) with the response headers of all the requests made; Each entry in the headers' array is an associative array in the form of property => value - body - an empty string as it is not available for this method; - response - the response given by the cURL library as an array with 2 entries: the first entry is the textual representation of the result's code, while second is the result's code itself; if the request was successful, these values will be array(CURLE_OK, 0); consult {@link http://www.php.net/manual/en/function.curl-errno.php#103128 this list} to see the possible values of this property; If the callback function returns FALSE while {@link cache} is enabled, the library will not cache the respective request, making it easy to retry failed requests without having to clear all cache. @return void |
$callback | mixed | |
return | void |