PHP5, MySQL5 & Apache2 on Debian Leny Slow

Discussion in 'Installation/Configuration' started by latheesan, Jan 5, 2011.

  1. latheesan

    latheesan New Member

    PHP5, MySQL5 & Apache2 Slow On Debian Leny VPS

    Hi,

    I am working on a simple API to retrieve some custom logs from my server.

    My server is a Debian Leny VPS with dedicated 2 Gb RAM and 1 dedicated core from host machine (which is about 2 Ghz atleast - last I checked).

    This is the script I am trying to run on my server:

    log_api.php
    PHP:
    <?php

    // Init
    $result_array = array();

    // Capture Data
    $log_type = isset($_GET['log_type']) ? intval($_GET['log_type']) : -1;

    // Proceed If Valid Log Type Requested
    if ($log_type 0)
    {
        
    // Connect To MySQL Server
        
    @mysql_connect('localhost''USERNAME''PASSWORD');
        @
    mysql_select_db('DATABASE');

        
    // Query Database
        
    $result = @mysql_query(sprintf("SELECT * FROM `log_table` WHERE `log_type` = %d"$log_type));

        
    // Build Result
        
    if (@mysql_num_rows($result) > 0)
        {
            
    $i 0;
            while (
    $row = @mysql_fetch_assoc($result))
            {
                
    $result_array[$i]['log_id'] = $row['log_id'];
                
    $result_array[$i]['timestamp'] = $row['timestamp'];
                
    $result_array[$i]['log_text'] = $row['log_text'];
                
    $i++;
            }
        }

        
    // Close MySQL Connection
        
    @mysql_close();
    }

    // Return Result
    echo base64_encode(serialize($result_array));

    ?>
    This is how i call my API from another server:

    api_test.php
    PHP:
    <?php

    // API Setting
    $api_url 'http://www.domain.com/log_api.php';

    // Call The API
    $result file_get_contents($api_url .'?log_type=1');

    // Debug API Response
    echo '<pre>';
    print_r(unserialize(base64_decode($result)));
    echo 
    '</pre>';

    ?>
    When I run the api_test.php from another server to test the "log api", i get the response immediately. When I press F5 again (second time), the response is also returned immediately. When I press F5 for the third time, it takes about 30 seconds (give or take) to get a response.

    The response also slows down after fourth, fifth ... etc refreshes. However, if i wait a while and refresh the page, this behaviour starts over (first two response is quick, then it slows down).

    Is this an issue related to my PHP5, MySQL5 or Apache2 configuration? Or is it something to do with my script?

    Here is my server configs:

    apache2.conf - http://pastebin.com/y8rSV0em
    php.ini - http://pastebin.com/Z3N86rKS
    my.cnf - http://pastebin.com/uP2t8Rvw

    Any idea..?
     
    Last edited: Jan 5, 2011
  2. falko

    falko Super Moderator ISPConfig Developer

    Are there any errors in Apache's error log?

    Is this an OpenVZ VPS? If so, what's the output of
    Code:
    cat /proc/user_beancounters
    ?
     
  3. latheesan

    latheesan New Member

    Hi Falko,

    I checked the error.log and there aren't any significant errors that occured, besides the usual ones like these:

    As for the VPS system, no I am not using OpenVZ or Xen, it's Hyper-V running on Windows Server 2008 R2 Standard OS.
     

Share This Page