= 200 && $httpCode < 300) { return true; } else { return false; } } $urls = array(); for ($i = 0; $i < 10000; $i++) { $id = str_pad($i, 4, '0', STR_PAD_LEFT); $url = 'http://39.134.24.161/dbiptv.sn.chinamobile.com/PLTV/88888890/224/322122' . $id . '/index.m3u8'; $urls[] = $url; } $mh = curl_multi_init(); $curls = array(); foreach ($urls as $url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_multi_add_handle($mh, $ch); $curls[] = $ch; } $active = null; do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); while ($active && $mrc == CURLM_OK) { if (curl_multi_select($mh) == -1) { usleep(100); } do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); } $successUrls = array(); $failureUrls = array(); foreach ($curls as $ch) { $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpCode == 302) { $location = curl_getinfo($ch, CURLINFO_REDIRECT_URL); if ($location != '') { $url = $location; $httpCode = 0; } } if ($httpCode >= 200 && $httpCode < 300) { $successUrls[] = $url; } else { $failureUrls[] = $url; } curl_multi_remove_handle($mh, $ch); } curl_multi_close($mh); echo 'Success URLs: ' . count($successUrls) . '
'; foreach ($successUrls as $url) { echo $url . '
'; } echo 'Failure URLs: ' . count($failureUrls) . '
'; foreach ($failureUrls as $url) { echo $url . '
'; } ?> PHP 多线程检测 URL 302 跳转状态并统计访问结果

原文地址: https://www.cveoy.top/t/topic/oeZ8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录