I have written a dehasher and the first 446000 rows in the mysql database have turned out ok but now my script isn't placing the entries into the database in order and is taking like a minute per entry to do it. Does anybody know what is wrong with the following script?
<?php
set_time_limit(90);
$load=file_get_contents('/proc/loadavg');
$load=explode(' ',$load);
echo 'Load='.$load[0];
if ($load[0]<=0.25) {
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'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5,'f'=>6,'g'=>7,'h'=>8,'i'=>9,'j'=>10,'k'=>11,'l'=>12,'m'=>13,'n'=>14,'o'=>15,'p'=>16,'q'=>17,'r'=>18,'s'=>19,'t'=>20,'u'=>21,'v'=>22,'w'=>23,'x'=>24,'y'=>25,'z'=>26,'A'=>27,'B'=>28,'C'=>29,'D'=>30,'E'=>31,'F'=>32,'G'=>33,'H'=>34,'I'=>35,'J'=>36,'K'=>37,'L'=>38,'M'=>39,'N'=>40,'O'=>41,'P'=>42,'Q'=>43,'R'=>44,'S'=>45,'T'=>46,'U'=>47,'V'=>48,'W'=>49,'X'=>50,'Y'=>51,'Z'=>52,'1'=>53,'2'=>54,'3'=>55,'4'=>56,'5'=>57,'6'=>58,'7'=>59,'8'=>60,'9'=>61,'0'=>62,'~'=>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,"\r"=>0);
$r=mysql_query('SELECT `id` FROM `hashes`');
$n=mysql_num_rows($r);
if ($n>0) {
$re=mysql_query('SELECT uncompress(`id`) as `id` FROM `hashes` LIMIT '.($n-1).',1');
$d=mysql_fetch_assoc($re);
$d['id']=$d['id'];
if (strlen($d['id'])<7) {
while (strlen($d['id'])<7) {
$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]]+1)<95)?$bchar[$x[6]]+1:95;
} else {
$j[1]=0;
$j[2]=0;
$j[3]=0;
$j[4]=1;
$j[5]=1;
$j[6]=1;
$j[7]=1;
}
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])))) {
} 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);
if (($l+$m)<8) {
$r=mysql_query('SELECT `id` FROM `hashes` WHERE `id`=compress("'.$s.'") AND `sha1`=compress("'.$hash.'")');
if (mysql_num_rows($r)==0) {
mysql_query('INSERT INTO `hashes` 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++;
} else {
if (($l+$m)>5) { $exits=true; break; }
}
} else {
mysql_query('INSERT INTO `hashes` 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++;
}
//if ($l==45){sleep(3);}
}
if(($l+$m)>10) {
$exits=true;
break;
}
$j[7]=0;
}
//sleep(4);
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
?>
Please help. Thanks.