Luminati PHP SDK
Library for making HTTP / HTTPS concurrent requests using curl_multi via the Luminati Service., (*1)
You will need at least a free Luminati Trial Account., (*2)
Installation
Install using composer:, (*3)
composer require rubobaquero/luminati
Usage
Instance a Luminati object with username, password and optional zone (gen by default):, (*4)
$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 function
- country
(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., (*5)
Example:, (*6)
$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 response
- url
: URL of the request
- request_info
: Information of the request given by curl_getinfo()
- user_data
: User data of the request
- time
: Execution time of the request, (*7)
Example:, (*8)
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:, (*9)
$luminati->make_requests($urls,5,20);