JavaScript
19
Вклад в тег
$proxyList = [
['ip' => '1.2.3.4', 'port' => '1234'],
['ip' => '4.3.2.1', 'port' => '5678'],
];
$requestOptions = [
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_CONNECTTIMEOUT => 3,
CURLOPT_TIMEOUT => 7,
];
$ch = curl_init('http://test.ru/get?a=1&b=2');
curl_setopt_array($ch, $requestOptions);
foreach ($proxyList as $item) {
curl_setopt($ch, CURLOPT_PROXY, $item['ip']);
curl_setopt($ch, CURLOPT_PROXYPORT, $item['port']);
$response = curl_exec($ch);
}
curl_close($ch);
use GuzzleHttp\Pool;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
$client = new Client();
$requests = function ($total) {
$uri = 'http://127.0.0.1:8126/guzzle-server/perf';
for ($i = 0; $i < $total; $i++) {
yield new Request('GET', $uri);
}
};
$pool = new Pool($client, $requests(100), [
'concurrency' => 5,
'fulfilled' => function ($response, $index) {
// this is delivered each successful response
},
'rejected' => function ($reason, $index) {
// this is delivered each failed request
},
]);
// Initiate the transfers and create a promise
$promise = $pool->promise();
// Force the pool of requests to complete.
$promise->wait();