php - cURL & Looping Through an Array -
i'm attempting create script cycle through array contain various file names use of curl & '404' error detection. in other words, if initial defaulted file name comes '404', create loop function cycle through array while still running through same curl session. , when detects status '200', stops loop & proceeds next value sent client. i've tried using foreach(), haven't had success. code i'm using start.
<?php if (isset($_post['request'])) { $req = $_post['request']; $url = $addr; $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_nobody, true); curl_exec($ch); if (curl_getinfo($ch, curlinfo_http_code) == '200') { echo $url; } curl_close($ch); } ?>
if (isset($_post['request'])) { $req = $_post['request']; $url = $addr; $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_nobody, true); curl_setopt($ch, curlopt_returntransfer , true); ($retry = 1; $retry <= $retry_max; $retry++) { $ret= curl_exec($ch); preg_match("/^http\/[01\.]+ ([0-9]{3}[a-za-z\(\)\- ]+)/",$ret,$getcode); if (strcmp($getcode[1], '200 ok') === 0) { break; } else { sleep(10); } } curl_close($ch); }
Comments
Post a Comment