Tony Manco avatar 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_%-?@]*)+)?'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.