www.webdeveloper.com
Results 1 to 3 of 3

Thread: Script checking http site code does not run on the server

  1. #1
    Join Date
    Apr 2013
    Posts
    2

    Script checking http site code does not run on the server

    Hello,

    I have a php script that is suppose to be checking http status code for submitted URL and return status number.
    Please see the code.
    Code:
    #!/usr/bin/php
    <?php
    
        $url = 'www.google.com';
    
        $connection = curl_init($url);
    
        curl_setopt($connection, CURLOPT_TIMEOUT, 30);
        curl_setopt($connection, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($connection, CURLOPT_HEADER, TRUE);
        curl_setopt($connection, CURLOPT_NOBODY, TRUE);
        curl_setopt($connection, CURLOPT_RETURNTRANSFER, TRUE);
    
        curl_exec($connection);
    
        $http_status = curl_getinfo($connection, CURLINFO_HTTP_CODE);
    
        curl_close($connection);
    
        echo "\nHTTP Status: $http_status\n";
    
        if ($http_status == 200 || $http_status == 302) {
            echo "Site is ok\n";
            exit;
    
            } else {
                echo "Site is not ok\n";
                exit;
    
                    }
    
    ?>
    When I run it on a local machine it is working well.
    If I run in on the server via console it returns error:
    "Operation timed out after 30 seconds with 0 bytes received"

    I have tried the same script on two other servers (via console) and it works.
    I have problem with one server only.
    I have checked php.ini on booth servers and they are exactly the same.
    I have changed httpd.conf file for Apache they are exactly the same.

    No idea what can be wrong.

    Any Idea guys?
    Thanks!
    Regards

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,536
    What happens if you ping the same domain from the problematic console?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Apr 2013
    Posts
    2
    Hello,

    Thanks for opening my eyes
    It was connecting to local IP address.
    Address was defined in etc/hosts file.

    Thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles