I'm not sure if this is possible but I'm kinda stuck in the middle. For my script I need to calculate the server load and the mysql cache usage both in percentage. Does anybody know of any scripts I can use for this. There are probably open source things that I'm not finding.

Ok, I found that the server load percentage is stored in /proc/loadavg but still need to find mysql's cache percentage. Also I'm not sure how often the /proc/loadavg file updates.

I just tested my code and turns out (I think) the mysql cache is calculated into the server load. So problem solved. Helps if you google these things for over an hour first. Now my server won't crash from server overload.

I have a problem in my script and if this problem can be solved my script should be complete. What my script does is it records every possible combination string into a database however some strings ending with a space are not being recorded. My full code is as follows:

<?php
set_time_limit(90);
$load=file_get_contents('/proc/loadavg');
$load=explode(' ',$load);
echo 'Load='.$load[0];
if ($load[0]<=0.60) {
mysql_connect('localhost','user','password');
mysql_select_db('database');
$char=array('','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u',
'v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T',
'U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0','~','`','!','@','#','$','%','^','&',
'*','(',')','-','_','+','=','\\','|','{','}','[',']',';',':','"','\'',',','<','.','>','?','/',' ');
$bchar=array(''=>0,'a'=>2,'b'=>3,'c'=>4,'d'=>5,'e'=>6,'f'=>7,'g'=>8,'h'=>9,'i'=>10,'j'=>11,
'k'=>12,'l'=>13,'m'=>14,'n'=>15,'o'=>16,'p'=>17,'q'=>18,'r'=>19,'s'=>20,'t'=>21,'u'=>22,
'v'=>23,'w'=>24,'x'=>25,'y'=>26,'z'=>27,'A'=>28,'B'=>29,'C'=>30,'D'=>31,'E'=>32,'F'=>33,
'G'=>34,'H'=>35,'I'=>36,'J'=>37,'K'=>38,'L'=>39,'M'=>40,'N'=>41,'O'=>42,'P'=>43,'Q'=>44,
'R'=>45,'S'=>46,'T'=>47,'U'=>48,'V'=>49,'W'=>50,'X'=>51,'Y'=>52,'Z'=>53,'1'=>54,'2'=>55,
'3'=>56,'4'=>57,'5'=>58,'6'=>59,'7'=>60,'8'=>61,'9'=>62,'0'=>63,'~'=>64,'`'=>65,'!'=>66,
'@'=>67,'#'=>68,'$'=>69,'%'=>70,'^'=>71,'&'=>72,'*'=>73,'('=>74,')'=>75,'-'=>76,'_'=>77,
'+'=>78,'='=>79,'\\'=>80,'|'=>81,'{'=>82,'}'=>83,'['=>84,']'=>85,';'=>86,
':'=>87,'"'=>88, '\''=>89,','=>90,'<'=>91,'.'=>92,'>'=>93,'?'=>94,'/'=>95,' '=>95,"\r"=>0);
$r=mysql_query('SELECT `id` FROM `hash`');
$n=mysql_num_rows($r);
if ($n>0) {
    $re=mysql_query('SELECT uncompress(`id`) as `id` FROM `hash` LIMIT '.($n-1).',1');
    $d=mysql_fetch_assoc($re);
    $d['id']=$d['id'];
    if (strlen($d['id'])<7) {
        while (strlen($d['id'])<=6) {
              $d['id']="\r".$d['id'];
              }
        }
    $x=str_split($d['id'],1);
    $j[1]=$bchar[$x[0]];
    $j[2]=$bchar[$x[1]];
    $j[3]=$bchar[$x[2]];
    $j[4]=$bchar[$x[3]];
    $j[5]=$bchar[$x[4]];
    $j[6]=$bchar[$x[5]];
    $j[7]=$bchar[$x[6]];
    } else {
    $j[1]=0;
    $j[2]=0;
    $j[3]=0;
    $j[4]=0;
    $j[5]=0;
    $j[6]=0;
    $j[7]=0;
    }
unset($bchar);
$m=0;
$l=0;
$p=true;
$passgo=0;
$sleeper=0;
for ($i[1]=$j[1];$i[1]<15;$i[1]++) { //16.0655625GB Database
    for ($i[2]=$j[2];isset($char[$i[2]]);$i[2]++) {
        for ($i[3]=$j[3];isset($char[$i[3]]);$i[3]++) {
            for ($i[4]=$j[4];isset($char[$i[4]]);$i[4]++) {
                for ($i[5]=$j[5];isset($char[$i[5]]);$i[5]++) {
                    for ($i[6]=$j[6];isset($char[$i[6]]);$i[6]++) {
                        $m+=$l;
                        $l=0;
                        for ($i[7]=$j[7];isset($char[$i[7]]);$i[7]++) {
                            if ((!empty($i[6]) && empty($i[7])) ||  (!empty($i[5]) && (empty($i[6]) || empty($i[7]))) ||  (!empty($i[4]) && (empty($i[5]) || empty($i[6]) || empty($i[7]))) ||  (!empty($i[3]) && (empty($i[4]) || empty($i[5]) || empty($i[6]) || empty($i[7]))) ||  (!empty($i[2]) && (empty($i[3]) || empty($i[4]) || empty($i[5]) || empty($i[6]) || empty($i[7]))) ||  (!empty($i[1]) && (empty($i[2]) || empty($i[3]) || empty($i[4]) || empty($i[5]) || empty($i[6]) || empty($i[7])))) {
                            echo $char[$i[1]].$char[$i[2]].$char[$i[3]].$char[$i[4]].$char[$i[5]].$char[$i[6]].$char[$i[7]].'<br>';
                            } else {
                            $v=$char[$i[1]].$char[$i[2]].$char[$i[3]].$char[$i[4]].$char[$i[5]].$char[$i[6]].$char[$i[7]];
                            $z=hash('sha1',$v);
                            $hash=mysql_real_escape_string(substr($z,0,4).hash('crc32',$z).hash('crc32b',$z));
                            $s=mysql_real_escape_string($v);
                            $r=mysql_query('SELECT `id` FROM `hash` WHERE `id`=compress("'.$s.'") AND `sha1`=compress("'.$hash.'")');
                            if (mysql_num_rows($r)==0 || $i[7]==' ') {
                                mysql_query('INSERT INTO `hash` SET `id`=compress("'.$s.'"), `crc32`=compress("'.mysql_real_escape_string(hash('crc32',$v)).'"), `crc32b`=compress("'.mysql_real_escape_string(hash('crc32b',$v)).'"), `sha1`=compress("'.$hash.'")');$l++;
                                }
                            $l++; if ($l==45){sleep(6);}
                            }
                            if(($l+$m)>140) {
                                $exits=true;
                                break;
                                }
                            $j[7]=0;
                            }
                        sleep(7);
                        if ($exits==true) { break; }
                        $j[6]=0;
                        }
                    if ($exits==true) { break; }
                    $j[5]=0;
                    }
                if ($exits==true) { break; }
                $j[4]=0;
                }
            if ($exits==true) { break; }
            $j[3]=0;
            }
        if ($exits==true) { break; }
        $j[2]=0;
        }
    if ($exits==true) { break; }
    $j[1]=0;
    }
flush();
} //end server load if

Does anybody know why some combinations with spaces are not being recorded. Also I checked the empty function and it returns false like it should when it checks for a space. Thanks.

I have just solved this and anybody who wants the use the above code are free to do so. Turns out the problem was that the hash for "a " or "a<space>" (without the quotes) had not been generated. This has been fixed and would like to see your comments on the effeciency of this code compared to what you have seen in the past.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.