S
S
Sergey2016-05-09 01:36:55
PHP
Sergey, 2016-05-09 01:36:55

How to check proxy with CURL?

Hello.
There is a login, password, IP and Port for working with a private proxy.
Before connecting and using it, I need to check if it is alive, as sometimes there are connection problems.
On VPS I use @fsockopen, but on regular hosting I need to implement it via CURL , which I still can't do, so I need help.
Here is the code that I wrote (more precisely found in Google), but it returns the following - Proxy is not working: couldn't connect to host

$proxy = 'login:[email protected]:8080';
$url = "https://www.google.com.ua/";
$ch = curl_init();  // Initialise a cURL handle
 
// Setting proxy option for cURL
if (isset($proxy)) {    // If the $proxy variable is set, then
    curl_setopt($ch, CURLOPT_PROXY, $proxy);    // Set CURLOPT_PROXY with proxy in $proxy variable
}
 
// Set any other cURL options that are required
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
 
$results = curl_exec($ch);  // Execute a cURL request
//curl_close($ch);    // Closing the cURL handle
if ($results === false) 
{
    echo "Proxy is not working: ", curl_error($ch);
} 
else 
{
    //print the output
    echo "OK";
}

Help me please!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-05-09
@Robotkos

And if in the browser through this proxy, then https://www.google.com.ua/ opens?
Try setting the CURLOPT_PROXY proxy address and CURLOPT_PROXYUSERPWD user separately.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question