rubobaquero / luminati
Class for making concurrent HTTP/HTTPS requests via Luminati service
v1.0.2
2016-02-03 16:34 UTC
Requires
- php: >=5.4
- marcushat/rolling-curl-x: *
This package is auto-updated.
Last update: 2024-12-13 12:17:35 UTC
README
Library for making HTTP / HTTPS concurrent requests using curl_multi via the Luminati Service.
You will need at least a free Luminati Trial Account.
Installation
Install using composer:
composer require rubobaquero/luminati
Usage
Instance a Luminati object with username, password and optional zone (gen by default):
$luminati = new Luminati($username,$password,"gen");
Prepare an array with a few requests. Each request is defined by an array with the following keys:
url
(mandatory): URL of the request.callback
(mandatory): Callback function that will be called with the result of the CURL request.options
(optional): CURL options of the request.user_data
(optional): Info that you will want to pass as parameter to the callback functioncountry
(optional): ISO Country code of the request.session
(optional): Luminati Session. If you want to make the requests using the same exit node yoy can specify one. If you don´t set any, a random one is generated.
Example:
$urls = array(); for($i=0;$i<10;$i++){ $urls[] = array( 'url' => 'https://www.wikipedia.org', 'options' => array( CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36" ), 'callback' => 'callback_func', 'user_data' => array( 'some' => 'useful data' ), 'country' => 'es' ); }
Then, write a callback function that accepts the following parameters:
response
: Body of the responseurl
: URL of the requestrequest_info
: Information of the request given by curl_getinfo()user_data
: User data of the requesttime
: Execution time of the request
Example:
function callback_func($response, $url, $request_info, $user_data, $time){ echo "We have a response from $url"; }
Finally, make 5 concurrent requests with a timeout of 20 seconds each one:
$luminati->make_requests($urls,5,20);