Answer the question
In order to leave comments, you need to log in
How not to execute a PHP script if the processed TXT file is empty?
There is a php code that checks the proxy from the gotovo_vse_sellery_bezdybley.txt file , and saves the results to the proxyuniq.txt file .
How to make the script below refuse to execute if the source file gotovo_vse_sellery_bezdybley.txt does not contain information - text (lines with proxies).
<?php
$proxies = file ("gotovo_vse_sellery_bezdybley.txt");
$proxies_out = array();
$mc = curl_multi_init ();
for ($thread_no = 0; $thread_no<count ($proxies); $thread_no++)
{
$c [$thread_no] = curl_init ();
curl_setopt ($c [$thread_no], CURLOPT_URL, "http://google.com");
curl_setopt ($c [$thread_no], CURLOPT_HEADER, 0);
curl_setopt ($c [$thread_no], CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($c [$thread_no], CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($c [$thread_no], CURLOPT_TIMEOUT, 10);
curl_setopt ($c [$thread_no], CURLOPT_PROXY, trim ($proxies [$thread_no]));
curl_setopt ($c [$thread_no], CURLOPT_PROXYTYPE, 0);
curl_multi_add_handle ($mc, $c [$thread_no]);
}
do {
while (($execrun = curl_multi_exec ($mc, $running)) == CURLM_CALL_MULTI_PERFORM);
if ($execrun != CURLM_OK) break;
while ($done = curl_multi_info_read ($mc))
{
$info = curl_getinfo ($done ['handle']);
if ($info ['http_code'] == 301) {
echo trim ($proxies [array_search ($done['handle'], $c)])."\r\n";
$proxies_out[trim($proxies[array_search($done['handle'], $c)])] = trim($proxies[array_search($done['handle'], $c)]);
}
curl_multi_remove_handle ($mc, $done ['handle']);
}
} while ($running);
curl_multi_close ($mc);
file_put_contents("proxyuniq.txt", implode("\r\n", $proxies_out));
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question