Answer the question
In order to leave comments, you need to log in
Is there any way to optimize this php code?
Hello.
I don't know if this code is shit or it just needs a lot of RAM on the server to execute it.
ini_set('max_execution_time', 900);
for ($i = 3000000 ; $i <= 3000120; $i++) {
$next = 'https://example.ru/novosti/politica.php?id='.$i;
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,$next);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$query = curl_exec($curl_handle);
curl_close($curl_handle);
$homepage = $query;
if (strpos($homepage, 'window.trackErrorPage') !== false)
{
$inexistente [] = $i;
}
else {
$existente [] = $i;
}
}
Answer the question
In order to leave comments, you need to log in
Тут ещё зависит от сервера, на который отправляются запросы. Возможно дело в этом? А вообще такое количество запросов лучше выполнять в несколько потоков.
And you open a browser, in it open the development tools, the "network" tab and then open one of your pages. Check out the download time.
Let's say this Toaster page loaded ~300ms for me, respectively, a million pages will be loaded in 300'000 seconds, or about three and a half days just to get the pages itself, without taking into account the costs of the script.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question