`curl`が機能せず、メッセージも表示されません。

`curl`が機能せず、メッセージも表示されません。

アドレスを確認するためにカールを使用するスクリプトがありますが、なぜ以下のようないくつかのアドレスで停止するのですか?それを防ぐにはどうすればよいですか?詳しくはこのアドレスを確認してください

curl https://10.10.34.36/test

私のスクリプト:

$sites = file_get_contents('./sites.json');
$sites = json_decode($sites);
function get_html_title($html){
    preg_match("/\<title.*\>(.*)\<\/title\>/isU", $html, $matches);
    return $matches[1];
}
function get_redirect_target($url)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_NOBODY, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); 
    
// The maximum number of seconds to allow cURL functions to execute.
    curl_setopt($ch, CURLOPT_TIMEOUT, 8); //timeout in seconds
    $headers = curl_exec($ch);
    curl_close($ch);

    $result = array("old"=>$url);
    // Check if there's a Location: header (redirect)
    if (preg_match('/^Location: (.+)$/im', $headers, $matches)){
        $result["new"] = trim($matches[1]); 
        $html = file_get_contents($result["new"]);
        $title = get_html_title($html);
        $result["title"] = trim($title); 
        return $result;
    }
       

    // If not, there was no redirect so return the original URL
    return "";
}
function get_redirect_final_target($url)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_NOBODY, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // follow redirects
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // set referer on redirect
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.105 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)");
    curl_exec($ch);
    $target = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    curl_close($ch);

    if ($target)
        return $target;

    return false;
}
$redirectsList = array();
foreach($sites as $key=>$site){
    $res=get_redirect_final_target($site->url);
    if($res!=$site->url){
    $html = file_get_contents($res);
    $title = get_html_title($html);
    $result["title"] = trim($title);     
    $newurl = ["old"=>$site->url,"new"=>$res,"title"=>$title];
        array_push($redirectsList,$newurl);
        $sites[$key]->url = $newurl['new'];
    }
}
file_put_contents('./sites5.json', json_encode($sites, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT));
echo '<table border="1">';
    echo '<tr>';
       echo '<td>Old url</td>';
       echo '<td>New url</td>';
       echo '<td>Title</td>';
    echo '</tr>';
foreach($redirectsList  as $record){
    echo '<tr>';
       echo '<td>'.$record['old'].'</td>';
       echo '<td>'.$record['new'].'</td>';
       echo '<td>'.$record['title'].'</td>';
    echo '</tr>';
}
echo '</table>';

私のJSONファイル:

[
    {
        "url": "https://10.10.34.36/test"
    },
    {
        "url": "https://google.com/"
    }
]

ベストアンサー1

それはプライベートIPアドレスです。あなたが持っているサーバーの種類を知ることは不可能です。しかし、curlそれがどれほど広くなっているか、どれだけうまくテストされたか、どれほど強力なのかを知ることは、次のように診断したいと思います。

10.10.34.36のサーバーがまったく存在しない場合、停止または誤動作する可能性があり、ネットワーク設定が何らかの方法で破損している可能性があります(プロキシが正しく構成されていないか、ホストへのパスがありません...)。これらすべてがcurlnbotよりうまく機能する可能性がはるかに高いです。

おすすめ記事