Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8905719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:27:57+00:00 2026-06-15T02:27:57+00:00

I am facing one unusual behavior of curl. For a given page, I some

  • 0

I am facing one unusual behavior of curl. For a given page, I some times get HTTP response code as 200 and sometimes I get 0 as HTTP response code. I am not able to understand whether this page is valid or not. If you try the given code, please try it for at least 5-10 times so that you can see the difference.

function print_info()
{
    $url = 'bart.no';
    $arr = array(
    'bart.no',
    'bolandirekt.nu',
    'ekompassen.com',
    'ekompassen.nu',
    );

    foreach ($arr as $url)
    {
        echo "<br/>URL: " . $url;
        $temp = str_replace(array("www.", "http://", "https://"), "", strtolower($url));

        // From this array it will be decided which is to prepend
        $pre_array = array("", "www.", "https://", "http://", "https://www.", "http://www.");
        $status_code = array();

        // For each Value Status will be stored
        foreach ($pre_array as $pre)
        {

            $options = array(
                CURLOPT_RETURNTRANSFER => TRUE, // return web page
                CURLOPT_HEADER => TRUE, // don't return headers
                CURLOPT_FOLLOWLOCATION => FALSE, // follow redirects
                CURLOPT_ENCODING => "", // handle all encodings
                CURLOPT_USERAGENT => "spider", // who am i
                CURLOPT_AUTOREFERER => FALSE, // set referer on redirect
                CURLOPT_SSL_VERIFYHOST => FALSE, //ssl verify host
                CURLOPT_SSL_VERIFYPEER => FALSE, //ssl verify peer
                CURLOPT_NOBODY => FALSE,
                CURLOPT_CONNECTTIMEOUT => 20, // timeout on connect
                CURLOPT_TIMEOUT => 20, // timeout on response
            );

            // Initializing Curl
            $ch = curl_init($pre . $temp);
            // Set Curl Options
            curl_setopt_array($ch, $options);
            // Execute Curl
            $content = curl_exec($ch);

            $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            echo "<pre/>";
            if ($code == 200)
            {
                print_r(curl_getinfo($ch));
                break;
            }           
                            curl_close($ch);
        }
    }
}

So my final doubt is : Why I am getting response code 200 for the pages which are not existing Or not opening in browser ? Also, why sometimes I get response code 0 and sometimes response code 200 for the same page even if I keep time interval between requests ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:27:59+00:00Added an answer on June 15, 2026 at 2:27 am

    The CURL request did not complete, thus there’s no response code.
    The reason for this may be an invalid host name (can’t resolve), malformed URL, timeout, etc.

    You should be able to get the CURL error code as in CodeCaster’s comment and curl_error / curl_errno docs.

    Once the CURL request completed properly, then a response code (from the server) should be available and meaningful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing one problem in Hibernate. Here is the code. Configuration cfg =
We are facing one issue directly connected with our Flash API we've given to
I am facing one issue related to pthread_cancel. Please see the code below: void*
Following is my code in which i am facing only one difficulty that when
I am facing some typical problem from one of my project. A section in
I am facing one JDBC exception (once in 100 times). But even in that
I am facing one problem in the following code , Form is going to
i am facing one problem i have two xml files. Plugins.xml <SolutionProfile xmlns=http://schemas.microsoft.com/pag/cab-profile> <Modules>
I am facing one issue related to multithreading because of shared code. I want
I am facing one error in follwoing code snippet.I tried debugging it but of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.