S
S
stamdyscias2016-02-26 16:57:08
PHP
stamdyscias, 2016-02-26 16:57:08

How to use proxy in php?

It is necessary to make a GET request for a specific resource and set the next proxy for each new request, how can this be done?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Sedyshev, 2016-02-26
@stamdyscias

$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);

D
Dmitry, 2016-02-26
@ExileeD

curl_setopt( $ch, CURLOPT_PROXY, $ip . ':' . $port );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question