Why proxies do not work with curl?

Hello!
Why the result of the function curl_exec proxy is always false?
Or works very rarely
UPD: Not working with proxy, which is port 8000.
UPD2: No, it also works with all, but not always
Code:
global $proxy;
 $proxyRand = rand(0, count($proxy) - 1);
 $proxySplit = preg_split("~:~", $proxy[$proxyRand]);
 $proxyCheck = curl_init('https://yandex.ru');
 curl_setopt($proxyCheck, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($proxyCheck, THIS, false);
 curl_setopt($proxyCheck, CURLOPT_HEADER, false);
 curl_setopt($proxyCheck, CURLOPT_FOLLOWLOCATION, true);
 curl_setopt($proxyCheck, CURLOPT_PROXY, $proxySplit[0]);
 curl_setopt($proxyCheck, CURLOPT_PROXYPORT, $proxySplit[1]);
 if ($proxySplit[2] != null and $proxySplit[3] != null) {
 curl_setopt($proxyCheck, CURLOPT_PROXYUSERPWD, $proxySplit[2].$proxySplit[3]);
}
 $proxyCheckExec = curl_exec($proxyCheck);
 if ($proxyCheckExec) {
curl_close($proxyCheck);
print("valid");
die("Stopped");
 if ($proxySplit[2] != null and $proxySplit[3] != null) {
 return ['ip_port' => $proxySplit[0].':'.$proxySplit[1], 'user_pass' => $proxySplit[2].":".$proxySplit[3]];
 } else {
 return ['ip_port' => $proxySplit[0].':'.$proxySplit[1]];
}

 }
April 7th 20 at 15:36
2 answers
April 7th 20 at 15:38
Solution
The problem was the extra space in the proxy sheet
April 7th 20 at 15:40
Rather then this:
global $proxy;
 $proxyRand = rand(0, count($proxy) - 1);
 $proxySplit = preg_split("~:~", $proxy[$proxyRand]);
 $proxyCheck = curl_init('https://yandex.ru');
 curl_setopt($proxyCheck, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($proxyCheck, THIS, false);
 curl_setopt($proxyCheck, CURLOPT_HEADER, false);
 curl_setopt($proxyCheck, CURLOPT_FOLLOWLOCATION, true);
 curl_setopt($proxyCheck, CURLOPT_PROXY, $proxySplit[0]);
 curl_setopt($proxyCheck, CURLOPT_PROXYPORT, $proxySplit[1]);
 if (!empty($proxySplit[2]) AND !empty($proxySplit[3])) {
 curl_setopt($proxyCheck, CURLOPT_PROXYUSERPWD, $proxySplit[2].':'.$proxySplit[3]);
}
 if (!$proxyCheckExec = curl_exec($proxyCheck)) {
curl_close($proxyCheck);
print("valid");
die("Stopped");
 if (!empty($proxySplit[2]) AND !empty($proxySplit[3])) {
 return ['ip_port' => $proxySplit[0].':'.$proxySplit[1], 'user_pass' => $proxySplit[2].":".$proxySplit[3]];
 } else {
 return ['ip_port' => $proxySplit[0].':'.$proxySplit[1]];
}
}
 else {
die(curl_error($proxyCheck));
 }

Find more questions by tags PHP