Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2003
    Posts
    543

    Writing a server monitor script problem.

    Hiya,

    Well Im a fairly experienced web developer trying to create a http monitor script. Now Ive built it, and the script runs every 5 minutes. It uses curl to perform a simple http request on a defined url however every now and then I get one of the two different errors (both the same but just a difference with the bytes received).

    Operation timed out with 0 out of -1 bytes received

    Operation timed out with 55 out of -1 bytes received

    It happens about every 1 or 2 times an hour. So lets see the code:

    PHP Code:
    function check_http($server_id)
    {
        
    $server server_details($server_id);
        
        
    $url "http://" $server["domain"] . "/";
        
        
    $ch curl_init();
        
    curl_setopt($chCURLOPT_URL$url);
        
    curl_setopt($chCURLOPT_USERAGENT'Advanced Server Monitor');
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
    curl_setopt($chCURLOPT_TIMEOUT10); // times out after 10s 
        
    curl_setopt($chCURLOPT_HEADER0);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
        
    $curl_content curl_exec ($ch);
        
    $curl_info curl_getinfo($ch);
        
    $curl_error curl_error ($ch);
        
    curl_close ($ch);
        
        if (
    $curl_error)
            {
            
    log_error ($server_id"HTTP"$curl_error);
            return;
            }
        
        if (!
    eregi("^2([0-9]{2})"$curl_info['http_code']))
            {
            
    log_error ($server_id"HTTP""Error Code: " $curl_info['http_code']);
            return;
            }

    Now its pretty easy the code just retrieves the url and catches the response. The problem lies with $curl_error as that reports the Operation times out error. My question and problem is WHY.

    I have checked the http logs and it usually reports a log like this:

    206.xxx.xxx.xxx - - [13/Jun/2005:05:05:11 -0500] "GET /status.php HTTP/1.1" 200 55

    Notice that its transferred 55 bytes Also note that there are no errors reported.

    So Im at this stage now stuck with a big problem. If anyone can assist me in debugging this further I would love for you to reply!!!
    Off Topic Web Forum - A forum for talking about anything!!
    N.Z. Webmaster Community - Are you from New Zealand? Well signup to our forum!!!!

  2. #2
    Join Date
    Apr 2003
    Location
    UK
    Posts
    2,560
    i wrote a similar thing, but with netcat.. made things a lot simpler!

    curl_setopt($ch, CURLOPT_TIMEOUT, 10); // times out after 10s

    try upping the timeout? it might be that the webserver just happens to be busy at that particular time? up it to 60 seconds for say 6 hours and see if you still get those timeouts. im guessing the flaw in my argument is that you see the log of it actually getting the file... how much data does it transfer on a successful transfer?

    id make it throw up an error only if several sequential checks fail, or x fail in y period of time - less chance to throw up an error due to network probs etc

  3. #3
    Join Date
    Feb 2003
    Posts
    543
    I have tried the timeout at 120 and it made no difference :-(

    I also have a sequential check. If two errors in a row (ie 2 within 13 minutes ) are detected then the alarm gets triggered.

    Im investigating tcpdump to check if there are packets being lost in the network but at a biginner at that...

    Keep the suggestions coming please! :-)
    Off Topic Web Forum - A forum for talking about anything!!
    N.Z. Webmaster Community - Are you from New Zealand? Well signup to our forum!!!!

  4. #4
    Join Date
    Apr 2003
    Location
    UK
    Posts
    2,560
    thats ok if you've got unique ip addresses etc, otherwise you might lose it in the noise!

Posting Permissions

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