true, CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36', CURLOPT_COOKIE => 'sid=1', CURLOPT_ENCODING => "deflate" )); $hits = 0; $last_request_time = 0; $hits_per_req = 3; $req_period = 1000; $i = 1; while (true) { $res = request($ch, 'http://spaces.ru/mail2/?r=mail/contact_list&List=3&P='.$i); preg_match_all("/this,(\{.*?\})/si", $res, $jsons); $is_email_exists = false; foreach ($jsons[1] as $json) { $contact =json_decode(str_replace("'", '"', $json), true); echo $contact['userName']."\n"; if (isset($contact['spamLink']) && $contact['spamLink']) { request($ch, $contact['spamLink']); $is_email_exists = true; } // elseif (isset($contact['archiveLink']) && $contact['archiveLink']) { // request($ch, $contact['archiveLink']); // } } if (!$is_email_exists) ++$i; if ($i > 63) exit("EXIT"); if (!$jsons[1]) exit("DONE!\n"); } function request($ch, $url) { global $last_request_time, $hits_per_req, $req_period, $hits; $diff = (microtime(true) - $last_request_time) * 1000; if ($diff < $req_period) { if ($hits >= $hits_per_req) { usleep(($req_period - $diff) * 1000); $hits = 0; } } else { $hits = 0; } curl_setopt($ch, CURLOPT_URL, $url); $res = curl_exec($ch); $last_request_time = microtime(true); ++$hits; return $res; }