Commits

Tony Manco committed ba334bf

Added command to display memory usage

Comments (0)

Files changed (1)

         $this->arcpath = $arcpath;
         $this->archive = $archive;
         $this->modpath = $modpath;
-        $this->version = "phIRCe v0.4";
+        $this->version = "phIRCe v0.50";
 
         $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
         die_unless($this->socket, "socket_create() failed: reason: "
             case "!license":
                 $this->DisplayLicense($from);
                 break;
+            case "!memory":
+                $this->SendCommand("PRIVMSG $chan :\x02Memory in use:\x02 "
+                        .$this->MemoryUsage()." MB | \x02Peak usage:\x02 "
+                            .$this->PeakMemoryUsage()." MB \r\n");
+                break;
             default:
                 //$this->SendCommand("PRIVMSG $chan :Not a valid command!\r\n");
                 break;
         $this->modules = $modules;
     }
 
+    private function MemoryUsage() {
+        // Returns memry usage in MB
+        $usage = (memory_get_usage() / 1024);
+        return round($usage / 1024, 3);
+    }
+
+    private function PeakMemoryUsage() {
+       // Returns memry usage in MB
+       $peak = (memory_get_peak_usage() / 1024);
+       return round($peak / 1024, 3);
+    }
     private function IsURL($line) {
         return preg_match('/(https?:\/\/)(www\.)?([a-zA-Z0-9]*\.)?([a-zA-Z0-9_%-]*)'
                         .'\b\.[a-z]{2,4}(\[a-z]{2})?((\/[a-zA-Z0-9_%-?@]*)+)?'