Как можно ускорить выполнение запроса? На один запрос уходит примерно 8 секунд.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Result</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
</head>
<body>
<?php
ini_set('max_execution_time', 6000);
// captcha settings
require __DIR__ . '/h_captha/autoloader.php';
$solver = new \TwoCaptcha\TwoCaptcha('//');
$captcha = "";
//parse input mails
$res = file_get_contents($_FILES['filename']['tmp_name']);
$lines = explode(",", $res);
// create result file
$file_name = $_POST['file_name'];
$filename = __DIR__ . '/results/'.$file_name.'_'.date('Y-m-d').'.txt';
$result_str = "PARSE INDEED".date('Y-m-d').' r\n';
$fh = fopen($filename, 'c');
fseek($fh, 0, SEEK_END);
fwrite($fh, PHP_EOL . $new_str);
fclose($fh);
// curl settings
$headers = [];
$headers[] = 'Authority: secure.indeed.com';
$headers[] = 'Accept: */*';
$headers[] = 'Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,id;q=0.6';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$headers[] = 'Origin: https://secure.indeed.com';
$headers[] = 'Referer: https://secure.indeed.com/auth';
$headers[] = 'Sec-Ch-Ua: ^^Google';
$headers[] = 'Sec-Ch-Ua-Mobile: ?0';
$headers[] = 'Sec-Ch-Ua-Platform: ^^Windows^^\"\"';
$headers[] = 'Sec-Fetch-Dest: empty';
$headers[] = 'Sec-Fetch-Mode: cors';
$headers[] = 'Sec-Fetch-Site: same-origin';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36';
//start parsing
for ($i=0; $i < count($lines); $i++) {
$val = $lines[$i];
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, "__email={$val}&form_tk=1gdv9jfkjkojc800&h-captcha-response={$captcha}");
curl_setopt($ch, CURLOPT_URL, 'https://secure.indeed.com/account/emailvalidation');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
$json_res = json_decode($data, true);
$data = $json_res['isEmailTaken'];
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
flush();
}
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($code == 429) {
//if indeed need captcha
try {
$result = $solver->hcaptcha([
'sitekey' => '7734ec9b-f8cb-44b2-9fac-3a502cb4f1bf',
'url' => 'https://secure.indeed.com/auth',
]);
} catch (\Exception $e) {
die($e->getMessage());
}
$captcha = $result->code;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, "__email={$val}&form_tk=1gdv9jfkjkojc800&h-captcha-response={$captcha}");
curl_setopt($ch, CURLOPT_URL, 'https://secure.indeed.com/account/emailvalidation');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
$json_res = json_decode($data, true);
$data = $json_res['isEmailTaken'];
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
flush();
}
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($data == true) {
echo $val . " : <span class='green'>Registered</span><br><br>";
flush();
$result_str = $val . " : Registered ";
$fh = fopen($filename, 'c');
fseek($fh, 0, SEEK_END);
fwrite($fh, PHP_EOL . $result_str);
fclose($fh);
}
} else {
if ($data == true) {
echo $val . " : <span class='green'>Registered</span><br><br>";
flush();
$result_str = $val . " : Registered ";
$fh = fopen($filename, 'c');
fseek($fh, 0, SEEK_END);
fwrite($fh, PHP_EOL . $result_str);
fclose($fh);
}
}
};
?>
<a href="<?php echo 'results/' . $file_name.'_'.date('Y-m-d').'.txt' ?>"><button type="submit" class="btn btn-primary">Download result</button></a>
<style>
.green{
border-bottom: 2px solid green;
}
.red{
border-bottom: 2px solid red;
}
</style>
</body>
</html>