Need this simple PHP code working!! Easy job $5 paypal!

Discussion in 'Programming' started by lachrymologist, Mar 16, 2009.

  1. #1
    i need this script working to monitor bandwidth of a folder/subdomain
    this script basically grabs the stats from cpanel.

    should be easy for knowledgeable coder. paying $5 for this quick job!
    pm me if you can do it
    
    <?
    function cpanel_logs( $username, $password, $domain, $searchpath )
    {
    	$bw = 0 ;
    	$logs = file( sprintf(  'http://%s:%s@%s:2082/getlogarchive/%s', 
    							$username, 
    							$password, 
    							$domain, 
    							$domain ));
    	if( $logs )
    	{
    		foreach( $logs as $line )
    		{
    			preg_match( '~"([A-Z]+) (.*?[^ ]) HTTP/1\.[1|0]" ([0-9]+) ([0-9]+) "(.*?[^"])" "(.*?[^"])"~si', 
    						$line, 
    						$matches 
    			);
    			
    			if( ereg( $searchpath, $matches[2] ) )
    			{
    				$bw += $matches[4];		
    			}
    		}
    	}
    	
    	return $bw ;
    }
    
    $username = 'username';
    $password = 'password';
    $hostname = 'hostname.com';
    
    printf( 'Images on %s have taken up a total of %01.2fMB bandwidth today<br />',
    		$hostname,
    		cpanel_logs( $username, $password, $hostname, 'images' ) / 1048576 
    );
    		
    printf( '%s has taken up a total of %01.2fMB bandwidth today<br />',
    		$hostname,
    		cpanel_logs( $username, $password, $hostname, '/' ) / 1048576 
    );
    ?>
    
    PHP:
     
    lachrymologist, Mar 16, 2009 IP
  2. chmdznr

    chmdznr Active Member

    Messages:
    417
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    log file usually returned as gzipped archive. before you regex-it, you should open it as gz file. So, instead of:
    $logs = file( sprintf(  'http://%s:%s@%s:2082/getlogarchive/%s', 
                                $username, 
                                $password, 
                                $domain, 
                                $domain ));
    PHP:
    You should use:
    $logs = readgzfile( sprintf(  'http://%s:%s@%s:2082/getlogarchive/%s', 
                                $username, 
                                $password, 
                                $domain, 
                                $domain ));
    PHP:
    just my two cents.
     
    chmdznr, Mar 16, 2009 IP