943,914 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1890
  • PHP RSS
Sep 18th, 2009
0

Calculating Recourses

Expand Post »
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.
Similar Threads
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Sep 18th, 2009
0

Re: Calculating Recourses

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.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Sep 18th, 2009
0

Re: Calculating Recourses

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.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Sep 18th, 2009
0

Re: Calculating Recourses

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

Re: Calculating Recourses

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.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Retrieving specific data from CSV file
Next Thread in PHP Forum Timeline: PHP Nav Edit Buttons





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC