Completed
Push — 0.x ( a2b070...a5c73d )
by Akihito
09:21
created
src/Dev/Application/ApplicationReflector.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@
 block discarded – undo
127 127
     /**
128 128
      * @param string $uri
129 129
      *
130
-     * @return array      [$filePath, $fileContents]
130
+     * @return string[]      [$filePath, $fileContents]
131 131
      * @throws InvalidUri
132 132
      */
133 133
     public function getNewResource($uri)
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     private function getResourcesUris()
77 77
     {
78 78
         $resources = [];
79
-        $resourceDir = $this->appDir . '/Resource';
79
+        $resourceDir = $this->appDir.'/Resource';
80 80
         $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($resourceDir), RecursiveIteratorIterator::SELF_FIRST);
81 81
         foreach ($iterator as $item) {
82 82
             /** @var $item \SplFileInfo */
@@ -99,11 +99,11 @@  discard block
 block discarded – undo
99 99
      */
100 100
     private function getUri(\SplFileInfo $file, $resourceDir)
101 101
     {
102
-        $relativePath = strtolower(str_replace($resourceDir . '/', '', (string) $file));
102
+        $relativePath = strtolower(str_replace($resourceDir.'/', '', (string) $file));
103 103
         $path = explode('/', $relativePath);
104 104
         $scheme = array_shift($path);
105 105
         $appName = 'self';
106
-        $uri = "{$scheme}://{$appName}/" . implode('/', $path);
106
+        $uri = "{$scheme}://{$appName}/".implode('/', $path);
107 107
         $uri = substr($uri, 0, -4);
108 108
 
109 109
         return $uri;
@@ -140,16 +140,16 @@  discard block
 block discarded – undo
140 140
         $path = implode('/', array_map('ucwords', explode('/', $path)));
141 141
         $path = str_replace('//', '/', $path);
142 142
         // cut head /
143
-        $filePath = $this->appDir . '/Resource/' . ucwords($url['scheme']) . $path . '.php';
144
-        $fileContents = file_get_contents(__DIR__ . '/resource.tpl');
143
+        $filePath = $this->appDir.'/Resource/'.ucwords($url['scheme']).$path.'.php';
144
+        $fileContents = file_get_contents(__DIR__.'/resource.tpl');
145 145
         $fileContents = str_replace('{$app}', $this->appName, $fileContents);
146
-        $paths = explode('/', $this->appName . $path);
146
+        $paths = explode('/', $this->appName.$path);
147 147
         $class = array_pop($paths);
148 148
         $appName = array_shift($paths);
149 149
         $scheme = ucwords($url['scheme']);
150 150
         $namespace = "{$appName}\\Resource\\{$scheme}";
151 151
         if (count($paths) > 0) {
152
-            $namespace .= '\\' . implode('\\', $paths);
152
+            $namespace .= '\\'.implode('\\', $paths);
153 153
         }
154 154
         $fileContents = str_replace('{$namespace}', $namespace, $fileContents);
155 155
         $fileContents = str_replace('{$class}', $class, $fileContents);
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         }
206 206
         $params = [];
207 207
         foreach ($allow as $method) {
208
-            $refMethod = new \ReflectionMethod($ro, 'on' . $method);
208
+            $refMethod = new \ReflectionMethod($ro, 'on'.$method);
209 209
             $parameters = $refMethod->getParameters();
210 210
             $paramArray = [];
211 211
             foreach ($parameters as $parameter) {
Please login to merge, or discard this patch.
src/Dev/Debug/ExceptionHandle/ExceptionHandler.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     /**
81 81
      * Set response
82 82
      *
83
-     * @param mixed             $exceptionTpl
83
+     * @param string             $exceptionTpl
84 84
      * @param ResponseInterface $response
85 85
      * @param ResourceObject    $errorPage
86 86
      *
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
     /**
125 125
      * Return error page
126 126
      *
127
-     * @param                               $e
127
+     * @param                               Exception $e
128 128
      * @param \BEAR\Resource\ResourceObject $response
129 129
      *
130 130
      * @return \BEAR\Resource\ResourceObject
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
     /**
241 241
      * Return log file path
242 242
      *
243
-     * @param $exceptionId
243
+     * @param string $exceptionId
244 244
      *
245 245
      * @return string
246 246
      */
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
     ) {
95 95
         $this->viewTemplate = $exceptionTpl;
96 96
         $this->response = $response;
97
-        $this->errorPage = $errorPage ? : new ErrorPage;
97
+        $this->errorPage = $errorPage ?: new ErrorPage;
98 98
     }
99 99
 
100 100
     /**
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
      */
133 133
     private function buildErrorPage($e, ResourceObject $response)
134 134
     {
135
-        $exceptionId = 'e' . $response->code . '-' . substr(md5((string) $e), 0, 5);
135
+        $exceptionId = 'e'.$response->code.'-'.substr(md5((string) $e), 0, 5);
136 136
         try {
137 137
             throw $e;
138 138
         } catch (ResourceNotFound $e) {
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
         }
180 180
         $response->headers['X-EXCEPTION-CLASS'] = get_class($e);
181 181
         $response->headers['X-EXCEPTION-MESSAGE'] = str_replace(PHP_EOL, ' ', $e->getMessage());
182
-        $response->headers['X-EXCEPTION-CODE-FILE-LINE'] = '(' . $e->getCode() . ') ' . $e->getFile(
183
-        ) . ':' . $e->getLine();
184
-        $previous = $e->getPrevious() ? (get_class($e->getPrevious()) . ': ' . str_replace(
182
+        $response->headers['X-EXCEPTION-CODE-FILE-LINE'] = '('.$e->getCode().') '.$e->getFile(
183
+        ).':'.$e->getLine();
184
+        $previous = $e->getPrevious() ? (get_class($e->getPrevious()).': '.str_replace(
185 185
             PHP_EOL,
186 186
             ' ',
187 187
             $e->getPrevious()->getMessage()
@@ -260,10 +260,10 @@  discard block
 block discarded – undo
260 260
         $data = (string) $e;
261 261
         $previousE = $e->getPrevious();
262 262
         if ($previousE) {
263
-            $data .= PHP_EOL . PHP_EOL . '-- Previous Exception --' . PHP_EOL . PHP_EOL;
263
+            $data .= PHP_EOL.PHP_EOL.'-- Previous Exception --'.PHP_EOL.PHP_EOL;
264 264
             $data .= $previousE->getTraceAsString();
265 265
         }
266
-        $data .= PHP_EOL . PHP_EOL . '-- Bindings --' . PHP_EOL . (string) $this->injector;
266
+        $data .= PHP_EOL.PHP_EOL.'-- Bindings --'.PHP_EOL.(string) $this->injector;
267 267
         $file = $this->getLogFilePath($exceptionId);
268 268
         if (is_writable($this->logDir)) {
269 269
             file_put_contents($file, $data);
Please login to merge, or discard this patch.
src/Module/Database/Dbal/Pager.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -173,7 +173,7 @@
 block discarded – undo
173 173
      *
174 174
      * @param $query
175 175
      *
176
-     * @return mixed
176
+     * @return string
177 177
      */
178 178
     public function getPagerQuery($query)
179 179
     {
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     {
59 59
         $this->db = $db;
60 60
 
61
-        $currentPage = $this->currentPage ? : (isset($_GET[$this->pageKey]) ? $_GET[$this->pageKey] : 1);
61
+        $currentPage = $this->currentPage ?: (isset($_GET[$this->pageKey]) ? $_GET[$this->pageKey] : 1);
62 62
         $this->firstResult = ($currentPage - 1) * $this->maxPerPage;
63 63
         $pagerfanta->setMaxPerPage($this->maxPerPage);
64 64
         $pagerfanta->setCurrentPage($currentPage, false, true);
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
      */
83 83
     private function getHtml(Pagerfanta $pagerfanta)
84 84
     {
85
-        $view = $this->view ? : new TwitterBootstrapView;
86
-        $routeGenerator = $this->routeGenerator ? : function ($page) {
85
+        $view = $this->view ?: new TwitterBootstrapView;
86
+        $routeGenerator = $this->routeGenerator ?: function($page) {
87 87
             return "?{$this->pageKey}={$page}";
88 88
         };
89 89
         $html = $view->render(
Please login to merge, or discard this patch.
src/Module/Di/DiCompilerProvider.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
 
46 46
     /**
47 47
      * @param string $appName
48
-     * @param string|string[] $context
48
+     * @param string $context
49 49
      * @param string $tmpDir
50 50
      * @param Cache  $cache
51 51
      *
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public function get($extraCacheKey = '')
68 68
     {
69
-        $contextKey = is_array($this->context)? implode('_', $this->context) : $this->context;
70
-        $saveKey = $this->appName . $contextKey;
69
+        $contextKey = is_array($this->context) ? implode('_', $this->context) : $this->context;
70
+        $saveKey = $this->appName.$contextKey;
71 71
         if (isset(self::$compiler[$saveKey])) {
72 72
             return self::$compiler[$saveKey];
73 73
         }
74
-        $moduleProvider = function () use ($saveKey) {
74
+        $moduleProvider = function() use ($saveKey) {
75 75
             // avoid infinity loop
76 76
             if (isset(self::$module[$saveKey])) {
77 77
                 return self::$module[$saveKey];
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 
82 82
             return self::$module[$saveKey];
83 83
         };
84
-        $cacheKey = $this->appName . $contextKey . $extraCacheKey;
84
+        $cacheKey = $this->appName.$contextKey.$extraCacheKey;
85 85
         self::$compiler[$saveKey] = $compiler = DiCompiler::create($moduleProvider, $this->cache, $cacheKey, $this->tmpDir);
86 86
 
87 87
         return $compiler;
Please login to merge, or discard this patch.
src/Provide/Application/DiLogger.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,6 @@
 block discarded – undo
20 20
     /**
21 21
      * log injection information
22 22
      *
23
-     * @param string        $class
24 23
      * @param array         $params
25 24
      * @param array         $setter
26 25
      * @param object        $object
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,14 +28,14 @@  discard block
 block discarded – undo
28 28
      */
29 29
     public function log(BoundDefinition $definition, array $params, array $setter, $object, Bind $bind)
30 30
     {
31
-        $toStr = function ($params) {
31
+        $toStr = function($params) {
32 32
             foreach ($params as &$param) {
33 33
                 if (is_object($param)) {
34
-                    $param = get_class($param) . '#' . spl_object_hash($param);
34
+                    $param = get_class($param).'#'.spl_object_hash($param);
35 35
                 } elseif (is_callable($param)) {
36 36
                     $param = "(callable) {$param}";
37 37
                 } elseif (is_scalar($param)) {
38
-                    $param = '(' . gettype($param) . ') ' . (string) $param;
38
+                    $param = '('.gettype($param).') '.(string) $param;
39 39
                 } elseif (is_array($param)) {
40 40
                     $param = $str = str_replace(["\n", " "], '', print_r($param, true));
41 41
                 }
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
         };
45 45
         $constructor = $toStr($params);
46 46
         $constructor = $constructor ? $constructor : '';
47
-        $setter = $setter ? "setter[" . implode(', ', array_keys($setter)) . ']' : '';
47
+        $setter = $setter ? "setter[".implode(', ', array_keys($setter)).']' : '';
48 48
         $logMessage = "[DI] {$definition->class} construct[$constructor] {$setter}";
49 49
         $this->logMessages[] = $logMessage;
50 50
     }
Please login to merge, or discard this patch.
src/Provide/ApplicationLogger/ResourceLog/Writer/Zf2Log.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@
 block discarded – undo
59 59
     }
60 60
 
61 61
     /**
62
-     * @param $hasServerInfo
62
+     * @param boolean $hasServerInfo
63 63
      *
64 64
      * @return string
65 65
      */
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -46,10 +46,10 @@
 block discarded – undo
46 46
         $this->pageId = rtrim(base64_encode(pack('H*', md5($_SERVER['REQUEST_TIME_FLOAT']))), '=');
47 47
         $id = "{$this->pageId}";
48 48
         /** @var $logger \Zend\Log\LoggerInterface */
49
-        $msg = "id:{$id}\treq:" . $request->toUriWithMethod();
50
-        $msg .= "\tcode:" . $result->code;
51
-        $msg .= "\tbody:" . json_encode($result->body);
52
-        $msg .= "\theader:" . json_encode($result->headers);
49
+        $msg = "id:{$id}\treq:".$request->toUriWithMethod();
50
+        $msg .= "\tcode:".$result->code;
51
+        $msg .= "\tbody:".json_encode($result->body);
52
+        $msg .= "\theader:".json_encode($result->headers);
53 53
         $path = $this->getPath(isset($_SERVER['PATH_INFO']));
54 54
         $msg .= "\tpath:$path";
55 55
         try {
Please login to merge, or discard this patch.
src/Provide/ResourceView/DevTemplateEngineRenderer.php 2 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
      *
228 228
      * @param string $file
229 229
      *
230
-     * @return mixed
230
+     * @return string
231 231
      * @return string
232 232
      */
233 233
     private function makeRelativePath($file)
@@ -240,9 +240,9 @@  discard block
 block discarded – undo
240 240
     /**
241 241
      * Return label
242 242
      *
243
-     * @param                $body
243
+     * @param                string $body
244 244
      * @param ResourceObject $resourceObject
245
-     * @param                $templateFile
245
+     * @param                string $templateFile
246 246
      *
247 247
      * @return string
248 248
      */
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 
266 266
     /**
267 267
      * @param ResourceObject $resourceObject
268
-     * @param                $labelColor
268
+     * @param                string $labelColor
269 269
      * @param                $templateFile
270 270
      * @param                $body
271 271
      *
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
             $this->templateEngineAdapter->assignAll($resourceObject->body);
182 182
         }
183 183
         // rendering with original render
184
-        $view =  $this->templateEngineRenderer->render($resourceObject);
184
+        $view = $this->templateEngineRenderer->render($resourceObject);
185 185
 
186 186
         // add tool bar
187 187
         $resourceObject->view = $view;
@@ -273,10 +273,10 @@  discard block
 block discarded – undo
273 273
      */
274 274
     private function addResourceMetaInfo(ResourceObject $resourceObject, $labelColor, $templateFile, $body)
275 275
     {
276
-        $resourceName = ($resourceObject->uri ? : get_class($resourceObject));
276
+        $resourceName = ($resourceObject->uri ?: get_class($resourceObject));
277 277
         // code editor
278 278
         $ref = new ReflectionObject($resourceObject);
279
-        $codeFile = ($resourceObject instanceof WeavedInterface) ? $ref->getParentClass()->getFileName(): $ref->getFileName();
279
+        $codeFile = ($resourceObject instanceof WeavedInterface) ? $ref->getParentClass()->getFileName() : $ref->getFileName();
280 280
         $codeFile = $this->makeRelativePath($codeFile);
281 281
         $var = $this->getVar($resourceObject->body);
282 282
         $resourceKey = spl_object_hash($resourceObject);
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 
285 285
         $resourceBody = preg_replace_callback(
286 286
             '/<!-- resource(.*?)resource_tab_end -->/s',
287
-            function ($matches) {
287
+            function($matches) {
288 288
                 $uri = substr(explode(' ', $matches[1])[0], 1);
289 289
                 preg_match('/ <!-- resource_body_start -->(.*?)<!-- resource_body_end -->/s', $matches[1], $resourceBodyMatch);
290 290
                 return "<!-- resource:$uri -->{$resourceBodyMatch[1]}<!-- /resource:$uri -->";
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
         );
294 294
         $resourceBodyHtml = highlight_string($resourceBody, true);
295 295
         $info = $this->getResourceInfo($resourceObject);
296
-        $rmReturn = function ($str) {
296
+        $rmReturn = function($str) {
297 297
             return str_replace("\n", '', $str);
298 298
         };
299 299
         $result = <<<EOT
@@ -369,16 +369,16 @@  discard block
 block discarded – undo
369 369
         }
370 370
         array_walk_recursive(
371 371
             $body,
372
-            function (&$value) {
372
+            function(&$value) {
373 373
                 if ($value instanceof Request) {
374
-                    $value = '(Request)' . $value->toUri();
374
+                    $value = '(Request)'.$value->toUri();
375 375
                 }
376 376
                 if ($value instanceof ResourceObject) {
377 377
                     $value = $value->body;
378 378
                 }
379 379
                 if (is_object($value)) {
380 380
                     /** @var $value object */
381
-                    $value = '(object) ' . get_class($value);
381
+                    $value = '(object) '.get_class($value);
382 382
                 }
383 383
             }
384 384
         );
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
      */
414 414
     private function getParamsInfo(ResourceObject $resourceObject)
415 415
     {
416
-        $result = self::BADGE_ARGS . self::DIV_WELL;
416
+        $result = self::BADGE_ARGS.self::DIV_WELL;
417 417
         if (isset($resourceObject->headers[DevInvoker::HEADER_PARAMS])) {
418 418
             $params = json_decode($resourceObject->headers[DevInvoker::HEADER_PARAMS], true);
419 419
         } else {
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
         /** @noinspection PhpUndefinedVariableInspection */
442 442
         $result .= "<ul>{$paramInfo}</ul>";
443 443
 
444
-        return $result . '</div>';
444
+        return $result.'</div>';
445 445
     }
446 446
 
447 447
     /**
@@ -453,9 +453,9 @@  discard block
 block discarded – undo
453 453
      */
454 454
     private function getInterceptorInfo(ResourceObject $resourceObject)
455 455
     {
456
-        $result = self::BADGE_INTERCEPTORS . self::DIV_WELL;
456
+        $result = self::BADGE_INTERCEPTORS.self::DIV_WELL;
457 457
         if (!isset($resourceObject->headers[DevInvoker::HEADER_INTERCEPTORS])) {
458
-            return $result . 'n/a</div>';
458
+            return $result.'n/a</div>';
459 459
         }
460 460
         $result .= '<ul class="unstyled">';
461 461
         $interceptors = json_decode($resourceObject->headers[DevInvoker::HEADER_INTERCEPTORS], true);
@@ -486,9 +486,9 @@  discard block
 block discarded – undo
486 486
             $resourceObject->headers[CacheLoader::HEADER_CACHE],
487 487
             true
488 488
         ) : false;
489
-        $result = self::BADGE_CACHE . self::DIV_WELL;
489
+        $result = self::BADGE_CACHE.self::DIV_WELL;
490 490
         if ($cache === false) {
491
-            return $result . 'n/a</div>';
491
+            return $result.'n/a</div>';
492 492
         }
493 493
         $iconLife = self::ICON_LIFE;
494 494
         $iconTime = self::ICON_TIME;
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
             $result .= "Read {$iconLife} {$life} {$iconTime} {$time}";
509 509
         }
510 510
 
511
-        return $result . '</div>';
511
+        return $result.'</div>';
512 512
     }
513 513
 
514 514
     /**
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
     private function getProfileInfo(ResourceObject $resourceObject)
522 522
     {
523 523
         // memory, time
524
-        $result = self::BADGE_PROFILE . self::DIV_WELL;
524
+        $result = self::BADGE_PROFILE.self::DIV_WELL;
525 525
         if (isset($resourceObject->headers[DevInvoker::HEADER_EXECUTION_TIME])) {
526 526
             $time = number_format($resourceObject->headers[DevInvoker::HEADER_EXECUTION_TIME], 3);
527 527
         } else {
Please login to merge, or discard this patch.
var/www/admin/apc/apc.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -465,6 +465,10 @@
 block discarded – undo
465 465
 }
466 466
 
467 467
 // create menu entry
468
+/**
469
+ * @param integer $ob
470
+ * @param string $title
471
+ */
468 472
 function menu_entry($ob,$title) {
469 473
 	global $MYREQUEST,$MY_SELF;
470 474
 	if ($MYREQUEST['OB']!=$ob) {
Please login to merge, or discard this patch.
Spacing   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-$autoload = dirname(dirname(__DIR__)) . '/bootstrap/autoload.php';
3
+$autoload = dirname(dirname(__DIR__)).'/bootstrap/autoload.php';
4 4
 if (file_exists($autoload)) {
5 5
     include $autoload;
6 6
 }
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 
29 29
  */
30 30
 
31
-$VERSION='$Id$';
31
+$VERSION = '$Id$';
32 32
 
33 33
 ////////// READ OPTIONAL CONFIGURATION FILE ////////////
34 34
 if (file_exists("apc.conf.php")) include("apc.conf.php");
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 
37 37
 ////////// BEGIN OF DEFAULT CONFIG AREA ///////////////////////////////////////////////////////////
38 38
 
39
-defaults('USE_AUTHENTICATION',0);			// Use (internal) authentication - best choice if
39
+defaults('USE_AUTHENTICATION', 0); // Use (internal) authentication - best choice if
40 40
 											// no other authentication is available
41 41
 											// If set to 0:
42 42
 											//  There will be no further authentication. You
@@ -44,16 +44,16 @@  discard block
 block discarded – undo
44 44
 											// If set to 1:
45 45
 											//  You need to change ADMIN_PASSWORD to make
46 46
 											//  this work!
47
-defaults('ADMIN_USERNAME','apc'); 			// Admin Username
48
-defaults('ADMIN_PASSWORD','password');  	// Admin Password - CHANGE THIS TO ENABLE!!!
47
+defaults('ADMIN_USERNAME', 'apc'); // Admin Username
48
+defaults('ADMIN_PASSWORD', 'password'); // Admin Password - CHANGE THIS TO ENABLE!!!
49 49
 
50 50
 // (beckerr) I'm using a clear text password here, because I've no good idea how to let
51 51
 //           users generate a md5 or crypt password in a easy way to fill it in above
52 52
 
53 53
 //defaults('DATE_FORMAT', "d.m.Y H:i:s");	// German
54
-defaults('DATE_FORMAT', 'Y/m/d H:i:s'); 	// US
54
+defaults('DATE_FORMAT', 'Y/m/d H:i:s'); // US
55 55
 
56
-defaults('GRAPH_SIZE',200);					// Image size
56
+defaults('GRAPH_SIZE', 200); // Image size
57 57
 
58 58
 //defaults('PROXY', 'tcp://127.0.0.1:8080');
59 59
 
@@ -61,45 +61,45 @@  discard block
 block discarded – undo
61 61
 
62 62
 
63 63
 // "define if not defined"
64
-function defaults($d,$v) {
65
-	if (!defined($d)) define($d,$v); // or just @define(...)
64
+function defaults($d, $v) {
65
+	if (!defined($d)) define($d, $v); // or just @define(...)
66 66
 }
67 67
 
68 68
 // rewrite $PHP_SELF to block XSS attacks
69 69
 //
70
-$PHP_SELF= isset($_SERVER['PHP_SELF']) ? htmlentities(strip_tags($_SERVER['PHP_SELF'],''), ENT_QUOTES, 'UTF-8') : '';
70
+$PHP_SELF = isset($_SERVER['PHP_SELF']) ? htmlentities(strip_tags($_SERVER['PHP_SELF'], ''), ENT_QUOTES, 'UTF-8') : '';
71 71
 $time = time();
72 72
 $host = php_uname('n');
73
-if($host) { $host = '('.$host.')'; }
73
+if ($host) { $host = '('.$host.')'; }
74 74
 if (isset($_SERVER['SERVER_ADDR'])) {
75 75
   $host .= ' ('.$_SERVER['SERVER_ADDR'].')';
76 76
 }
77 77
 
78 78
 // operation constants
79
-define('OB_HOST_STATS',1);
80
-define('OB_USER_CACHE',2);
81
-define('OB_VERSION_CHECK',3);
79
+define('OB_HOST_STATS', 1);
80
+define('OB_USER_CACHE', 2);
81
+define('OB_VERSION_CHECK', 3);
82 82
 
83 83
 // check validity of input variables
84
-$vardom=array(
85
-	'OB'	=> '/^\d+$/',			// operational mode switch
86
-	'CC'	=> '/^[01]$/',			// clear cache requested
87
-	'DU'	=> '/^.*$/',			// Delete User Key
88
-	'SH'	=> '/^[a-z0-9]+$/',		// shared object description
89
-
90
-	'IMG'	=> '/^[123]$/',			// image to generate
91
-	'LO'	=> '/^1$/',				// login requested
92
-
93
-	'COUNT'	=> '/^\d+$/',			// number of line displayed in list
94
-	'SCOPE'	=> '/^[AD]$/',			// list view scope
95
-	'SORT1'	=> '/^[AHSMCDTZ]$/',	// first sort key
96
-	'SORT2'	=> '/^[DA]$/',			// second sort key
97
-	'AGGR'	=> '/^\d+$/',			// aggregation by dir level
84
+$vardom = array(
85
+	'OB'	=> '/^\d+$/', // operational mode switch
86
+	'CC'	=> '/^[01]$/', // clear cache requested
87
+	'DU'	=> '/^.*$/', // Delete User Key
88
+	'SH'	=> '/^[a-z0-9]+$/', // shared object description
89
+
90
+	'IMG'	=> '/^[123]$/', // image to generate
91
+	'LO'	=> '/^1$/', // login requested
92
+
93
+	'COUNT'	=> '/^\d+$/', // number of line displayed in list
94
+	'SCOPE'	=> '/^[AD]$/', // list view scope
95
+	'SORT1'	=> '/^[AHSMCDTZ]$/', // first sort key
96
+	'SORT2'	=> '/^[DA]$/', // second sort key
97
+	'AGGR'	=> '/^\d+$/', // aggregation by dir level
98 98
 	'SEARCH'	=> '~^[a-zA-Z0-9/_.-]*$~'			// aggregation by dir level
99 99
 );
100 100
 
101 101
 // cache scope
102
-$scope_list=array(
102
+$scope_list = array(
103 103
 	'A' => 'cache_list',
104 104
 	'D' => 'deleted_list'
105 105
 );
@@ -118,31 +118,31 @@  discard block
 block discarded – undo
118 118
 }
119 119
 
120 120
 // check parameter syntax
121
-foreach($vardom as $var => $dom) {
121
+foreach ($vardom as $var => $dom) {
122 122
 	if (!isset($_REQUEST[$var])) {
123
-		$MYREQUEST[$var]=NULL;
124
-	} else if (!is_array($_REQUEST[$var]) && preg_match($dom.'D',$_REQUEST[$var])) {
125
-		$MYREQUEST[$var]=$_REQUEST[$var];
123
+		$MYREQUEST[$var] = NULL;
124
+	} else if (!is_array($_REQUEST[$var]) && preg_match($dom.'D', $_REQUEST[$var])) {
125
+		$MYREQUEST[$var] = $_REQUEST[$var];
126 126
 	} else {
127
-		$MYREQUEST[$var]=$_REQUEST[$var]=NULL;
127
+		$MYREQUEST[$var] = $_REQUEST[$var] = NULL;
128 128
 	}
129 129
 }
130 130
 
131 131
 // check parameter sematics
132
-if (empty($MYREQUEST['SCOPE'])) $MYREQUEST['SCOPE']="A";
133
-if (empty($MYREQUEST['SORT1'])) $MYREQUEST['SORT1']="H";
134
-if (empty($MYREQUEST['SORT2'])) $MYREQUEST['SORT2']="D";
135
-if (empty($MYREQUEST['OB']))	$MYREQUEST['OB']=OB_HOST_STATS;
136
-if (!isset($MYREQUEST['COUNT'])) $MYREQUEST['COUNT']=20;
137
-if (!isset($scope_list[$MYREQUEST['SCOPE']])) $MYREQUEST['SCOPE']='A';
138
-
139
-$MY_SELF=
132
+if (empty($MYREQUEST['SCOPE'])) $MYREQUEST['SCOPE'] = "A";
133
+if (empty($MYREQUEST['SORT1'])) $MYREQUEST['SORT1'] = "H";
134
+if (empty($MYREQUEST['SORT2'])) $MYREQUEST['SORT2'] = "D";
135
+if (empty($MYREQUEST['OB']))	$MYREQUEST['OB'] = OB_HOST_STATS;
136
+if (!isset($MYREQUEST['COUNT'])) $MYREQUEST['COUNT'] = 20;
137
+if (!isset($scope_list[$MYREQUEST['SCOPE']])) $MYREQUEST['SCOPE'] = 'A';
138
+
139
+$MY_SELF =
140 140
 	"$PHP_SELF".
141 141
 	"?SCOPE=".$MYREQUEST['SCOPE'].
142 142
 	"&SORT1=".$MYREQUEST['SORT1'].
143 143
 	"&SORT2=".$MYREQUEST['SORT2'].
144 144
 	"&COUNT=".$MYREQUEST['COUNT'];
145
-$MY_SELF_WO_SORT=
145
+$MY_SELF_WO_SORT =
146 146
 	"$PHP_SELF".
147 147
 	"?SCOPE=".$MYREQUEST['SCOPE'].
148 148
 	"&COUNT=".$MYREQUEST['COUNT'];
@@ -150,10 +150,10 @@  discard block
 block discarded – undo
150 150
 // authentication needed?
151 151
 //
152 152
 if (!USE_AUTHENTICATION) {
153
-	$AUTHENTICATED=1;
153
+	$AUTHENTICATED = 1;
154 154
 } else {
155
-	$AUTHENTICATED=0;
156
-	if (ADMIN_PASSWORD!='password' && ($MYREQUEST['LO'] == 1 || isset($_SERVER['PHP_AUTH_USER']))) {
155
+	$AUTHENTICATED = 0;
156
+	if (ADMIN_PASSWORD != 'password' && ($MYREQUEST['LO'] == 1 || isset($_SERVER['PHP_AUTH_USER']))) {
157 157
 
158 158
 		if (!isset($_SERVER['PHP_AUTH_USER']) ||
159 159
 			!isset($_SERVER['PHP_AUTH_PW']) ||
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 			exit;
173 173
 
174 174
 		} else {
175
-			$AUTHENTICATED=1;
175
+			$AUTHENTICATED = 1;
176 176
 		}
177 177
 	}
178 178
 }
@@ -186,39 +186,39 @@  discard block
 block discarded – undo
186 186
 	apcu_delete($MYREQUEST['DU']);
187 187
 }
188 188
 
189
-if(!function_exists('apcu_cache_info')) {
189
+if (!function_exists('apcu_cache_info')) {
190 190
 	echo "No cache info available.  APC does not appear to be running.";
191 191
   exit;
192 192
 }
193 193
 
194 194
 $cache = apcu_cache_info();
195 195
 
196
-$mem=apcu_sma_info();
196
+$mem = apcu_sma_info();
197 197
 
198 198
 // don't cache this page
199 199
 //
200
-header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
200
+header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
201 201
 header("Cache-Control: post-check=0, pre-check=0", false);
202
-header("Pragma: no-cache");                                    // HTTP/1.0
202
+header("Pragma: no-cache"); // HTTP/1.0
203 203
 
204 204
 function duration($ts) {
205 205
     global $time;
206
-    $years = (int)((($time - $ts)/(7*86400))/52.177457);
207
-    $rem = (int)(($time-$ts)-($years * 52.177457 * 7 * 86400));
208
-    $weeks = (int)(($rem)/(7*86400));
209
-    $days = (int)(($rem)/86400) - $weeks*7;
210
-    $hours = (int)(($rem)/3600) - $days*24 - $weeks*7*24;
211
-    $mins = (int)(($rem)/60) - $hours*60 - $days*24*60 - $weeks*7*24*60;
206
+    $years = (int) ((($time - $ts) / (7 * 86400)) / 52.177457);
207
+    $rem = (int) (($time - $ts) - ($years * 52.177457 * 7 * 86400));
208
+    $weeks = (int) (($rem) / (7 * 86400));
209
+    $days = (int) (($rem) / 86400) - $weeks * 7;
210
+    $hours = (int) (($rem) / 3600) - $days * 24 - $weeks * 7 * 24;
211
+    $mins = (int) (($rem) / 60) - $hours * 60 - $days * 24 * 60 - $weeks * 7 * 24 * 60;
212 212
     $str = '';
213
-    if($years==1) $str .= "$years year, ";
214
-    if($years>1) $str .= "$years years, ";
215
-    if($weeks==1) $str .= "$weeks week, ";
216
-    if($weeks>1) $str .= "$weeks weeks, ";
217
-    if($days==1) $str .= "$days day,";
218
-    if($days>1) $str .= "$days days,";
219
-    if($hours == 1) $str .= " $hours hour and";
220
-    if($hours>1) $str .= " $hours hours and";
221
-    if($mins == 1) $str .= " 1 minute";
213
+    if ($years == 1) $str .= "$years year, ";
214
+    if ($years > 1) $str .= "$years years, ";
215
+    if ($weeks == 1) $str .= "$weeks week, ";
216
+    if ($weeks > 1) $str .= "$weeks weeks, ";
217
+    if ($days == 1) $str .= "$days day,";
218
+    if ($days > 1) $str .= "$days days,";
219
+    if ($hours == 1) $str .= " $hours hour and";
220
+    if ($hours > 1) $str .= " $hours hours and";
221
+    if ($mins == 1) $str .= " 1 minute";
222 222
     else $str .= " $mins minutes";
223 223
     return $str;
224 224
 }
@@ -234,207 +234,207 @@  discard block
 block discarded – undo
234 234
 		exit(0);
235 235
 	}
236 236
 
237
-	function fill_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1,$color2,$text='',$placeindex=0) {
238
-		$r=$diameter/2;
239
-		$w=deg2rad((360+$start+($end-$start)/2)%360);
237
+	function fill_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1, $color2, $text = '', $placeindex = 0) {
238
+		$r = $diameter / 2;
239
+		$w = deg2rad((360 + $start + ($end - $start) / 2) % 360);
240 240
 
241 241
 
242 242
 		if (function_exists("imagefilledarc")) {
243 243
 			// exists only if GD 2.0.1 is avaliable
244
-			imagefilledarc($im, $centerX+1, $centerY+1, $diameter, $diameter, $start, $end, $color1, IMG_ARC_PIE);
244
+			imagefilledarc($im, $centerX + 1, $centerY + 1, $diameter, $diameter, $start, $end, $color1, IMG_ARC_PIE);
245 245
 			imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color2, IMG_ARC_PIE);
246
-			imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color1, IMG_ARC_NOFILL|IMG_ARC_EDGED);
246
+			imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color1, IMG_ARC_NOFILL | IMG_ARC_EDGED);
247 247
 		} else {
248 248
 			imagearc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color2);
249 249
 			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
250
-			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start+1)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
251
-			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end-1))   * $r, $centerY + sin(deg2rad($end))   * $r, $color2);
252
-			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end))   * $r, $centerY + sin(deg2rad($end))   * $r, $color2);
253
-			imagefill($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2, $color2);
250
+			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start + 1)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
251
+			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end - 1)) * $r, $centerY + sin(deg2rad($end)) * $r, $color2);
252
+			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end)) * $r, $centerY + sin(deg2rad($end)) * $r, $color2);
253
+			imagefill($im, $centerX + $r * cos($w) / 2, $centerY + $r * sin($w) / 2, $color2);
254 254
 		}
255 255
 		if ($text) {
256
-			if ($placeindex>0) {
257
-				imageline($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$diameter, $placeindex*12,$color1);
258
-				imagestring($im,4,$diameter, $placeindex*12,$text,$color1);
256
+			if ($placeindex > 0) {
257
+				imageline($im, $centerX + $r * cos($w) / 2, $centerY + $r * sin($w) / 2, $diameter, $placeindex * 12, $color1);
258
+				imagestring($im, 4, $diameter, $placeindex * 12, $text, $color1);
259 259
 
260 260
 			} else {
261
-				imagestring($im,4,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$text,$color1);
261
+				imagestring($im, 4, $centerX + $r * cos($w) / 2, $centerY + $r * sin($w) / 2, $text, $color1);
262 262
 			}
263 263
 		}
264 264
 	}
265 265
 
266
-	function text_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1,$text,$placeindex=0) {
267
-		$r=$diameter/2;
268
-		$w=deg2rad((360+$start+($end-$start)/2)%360);
266
+	function text_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1, $text, $placeindex = 0) {
267
+		$r = $diameter / 2;
268
+		$w = deg2rad((360 + $start + ($end - $start) / 2) % 360);
269 269
 
270
-		if ($placeindex>0) {
271
-			imageline($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$diameter, $placeindex*12,$color1);
272
-			imagestring($im,4,$diameter, $placeindex*12,$text,$color1);
270
+		if ($placeindex > 0) {
271
+			imageline($im, $centerX + $r * cos($w) / 2, $centerY + $r * sin($w) / 2, $diameter, $placeindex * 12, $color1);
272
+			imagestring($im, 4, $diameter, $placeindex * 12, $text, $color1);
273 273
 
274 274
 		} else {
275
-			imagestring($im,4,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$text,$color1);
275
+			imagestring($im, 4, $centerX + $r * cos($w) / 2, $centerY + $r * sin($w) / 2, $text, $color1);
276 276
 		}
277 277
 	}
278 278
 
279
-	function fill_box($im, $x, $y, $w, $h, $color1, $color2,$text='',$placeindex='') {
279
+	function fill_box($im, $x, $y, $w, $h, $color1, $color2, $text = '', $placeindex = '') {
280 280
 		global $col_black;
281
-		$x1=$x+$w-1;
282
-		$y1=$y+$h-1;
281
+		$x1 = $x + $w - 1;
282
+		$y1 = $y + $h - 1;
283 283
 
284
-		imagerectangle($im, $x, $y1, $x1+1, $y+1, $col_black);
285
-		if($y1>$y) imagefilledrectangle($im, $x, $y, $x1, $y1, $color2);
284
+		imagerectangle($im, $x, $y1, $x1 + 1, $y + 1, $col_black);
285
+		if ($y1 > $y) imagefilledrectangle($im, $x, $y, $x1, $y1, $color2);
286 286
 		else imagefilledrectangle($im, $x, $y1, $x1, $y, $color2);
287 287
 		imagerectangle($im, $x, $y1, $x1, $y, $color1);
288 288
 		if ($text) {
289
-			if ($placeindex>0) {
289
+			if ($placeindex > 0) {
290 290
 
291
-				if ($placeindex<16)
291
+				if ($placeindex < 16)
292 292
 				{
293
-					$px=5;
294
-					$py=$placeindex*12+6;
295
-					imagefilledrectangle($im, $px+90, $py+3, $px+90-4, $py-3, $color2);
296
-					imageline($im,$x,$y+$h/2,$px+90,$py,$color2);
297
-					imagestring($im,2,$px,$py-6,$text,$color1);
293
+					$px = 5;
294
+					$py = $placeindex * 12 + 6;
295
+					imagefilledrectangle($im, $px + 90, $py + 3, $px + 90 - 4, $py - 3, $color2);
296
+					imageline($im, $x, $y + $h / 2, $px + 90, $py, $color2);
297
+					imagestring($im, 2, $px, $py - 6, $text, $color1);
298 298
 
299 299
 				} else {
300
-					if ($placeindex<31) {
301
-						$px=$x+40*2;
302
-						$py=($placeindex-15)*12+6;
300
+					if ($placeindex < 31) {
301
+						$px = $x + 40 * 2;
302
+						$py = ($placeindex - 15) * 12 + 6;
303 303
 					} else {
304
-						$px=$x+40*2+100*intval(($placeindex-15)/15);
305
-						$py=($placeindex%15)*12+6;
304
+						$px = $x + 40 * 2 + 100 * intval(($placeindex - 15) / 15);
305
+						$py = ($placeindex % 15) * 12 + 6;
306 306
 					}
307
-					imagefilledrectangle($im, $px, $py+3, $px-4, $py-3, $color2);
308
-					imageline($im,$x+$w,$y+$h/2,$px,$py,$color2);
309
-					imagestring($im,2,$px+2,$py-6,$text,$color1);
307
+					imagefilledrectangle($im, $px, $py + 3, $px - 4, $py - 3, $color2);
308
+					imageline($im, $x + $w, $y + $h / 2, $px, $py, $color2);
309
+					imagestring($im, 2, $px + 2, $py - 6, $text, $color1);
310 310
 				}
311 311
 			} else {
312
-				imagestring($im,4,$x+5,$y1-16,$text,$color1);
312
+				imagestring($im, 4, $x + 5, $y1 - 16, $text, $color1);
313 313
 			}
314 314
 		}
315 315
 	}
316 316
 
317 317
 
318 318
 	$size = GRAPH_SIZE; // image size
319
-	if ($MYREQUEST['IMG']==3)
320
-		$image = imagecreate(2*$size+150, $size+10);
319
+	if ($MYREQUEST['IMG'] == 3)
320
+		$image = imagecreate(2 * $size + 150, $size + 10);
321 321
 	else
322
-		$image = imagecreate($size+50, $size+10);
322
+		$image = imagecreate($size + 50, $size + 10);
323 323
 
324 324
 	$col_white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
325
-	$col_red   = imagecolorallocate($image, 0xD0, 0x60,  0x30);
325
+	$col_red   = imagecolorallocate($image, 0xD0, 0x60, 0x30);
326 326
 	$col_green = imagecolorallocate($image, 0x60, 0xF0, 0x60);
327
-	$col_black = imagecolorallocate($image,   0,   0,   0);
328
-	imagecolortransparent($image,$col_white);
327
+	$col_black = imagecolorallocate($image, 0, 0, 0);
328
+	imagecolortransparent($image, $col_white);
329 329
 
330 330
 	switch ($MYREQUEST['IMG']) {
331 331
 
332 332
 	case 1:
333
-		$s=$mem['num_seg']*$mem['seg_size'];
334
-		$a=$mem['avail_mem'];
335
-		$x=$y=$size/2;
333
+		$s = $mem['num_seg'] * $mem['seg_size'];
334
+		$a = $mem['avail_mem'];
335
+		$x = $y = $size / 2;
336 336
 		$fuzz = 0.000001;
337 337
 
338 338
 		// This block of code creates the pie chart.  It is a lot more complex than you
339 339
 		// would expect because we try to visualize any memory fragmentation as well.
340 340
 		$angle_from = 0;
341
-		$string_placement=array();
342
-		for($i=0; $i<$mem['num_seg']; $i++) {
341
+		$string_placement = array();
342
+		for ($i = 0; $i < $mem['num_seg']; $i++) {
343 343
 			$ptr = 0;
344 344
 			$free = $mem['block_lists'][$i];
345 345
 			uasort($free, 'block_sort');
346
-			foreach($free as $block) {
347
-				if($block['offset']!=$ptr) {       // Used block
348
-					$angle_to = $angle_from+($block['offset']-$ptr)/$s;
349
-					if(($angle_to+$fuzz)>1) $angle_to = 1;
350
-					if( ($angle_to*360) - ($angle_from*360) >= 1) {
351
-						fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_red);
352
-						if (($angle_to-$angle_from)>0.05) {
353
-							array_push($string_placement, array($angle_from,$angle_to));
346
+			foreach ($free as $block) {
347
+				if ($block['offset'] != $ptr) {       // Used block
348
+					$angle_to = $angle_from + ($block['offset'] - $ptr) / $s;
349
+					if (($angle_to + $fuzz) > 1) $angle_to = 1;
350
+					if (($angle_to * 360) - ($angle_from * 360) >= 1) {
351
+						fill_arc($image, $x, $y, $size, $angle_from * 360, $angle_to * 360, $col_black, $col_red);
352
+						if (($angle_to - $angle_from) > 0.05) {
353
+							array_push($string_placement, array($angle_from, $angle_to));
354 354
 						}
355 355
 					}
356 356
 					$angle_from = $angle_to;
357 357
 				}
358
-				$angle_to = $angle_from+($block['size'])/$s;
359
-				if(($angle_to+$fuzz)>1) $angle_to = 1;
360
-				if( ($angle_to*360) - ($angle_from*360) >= 1) {
361
-					fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_green);
362
-					if (($angle_to-$angle_from)>0.05) {
363
-						array_push($string_placement, array($angle_from,$angle_to));
358
+				$angle_to = $angle_from + ($block['size']) / $s;
359
+				if (($angle_to + $fuzz) > 1) $angle_to = 1;
360
+				if (($angle_to * 360) - ($angle_from * 360) >= 1) {
361
+					fill_arc($image, $x, $y, $size, $angle_from * 360, $angle_to * 360, $col_black, $col_green);
362
+					if (($angle_to - $angle_from) > 0.05) {
363
+						array_push($string_placement, array($angle_from, $angle_to));
364 364
 					}
365 365
 				}
366 366
 				$angle_from = $angle_to;
367
-				$ptr = $block['offset']+$block['size'];
367
+				$ptr = $block['offset'] + $block['size'];
368 368
 			}
369 369
 			if ($ptr < $mem['seg_size']) { // memory at the end
370
-				$angle_to = $angle_from + ($mem['seg_size'] - $ptr)/$s;
371
-				if(($angle_to+$fuzz)>1) $angle_to = 1;
372
-				fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_red);
373
-				if (($angle_to-$angle_from)>0.05) {
374
-					array_push($string_placement, array($angle_from,$angle_to));
370
+				$angle_to = $angle_from + ($mem['seg_size'] - $ptr) / $s;
371
+				if (($angle_to + $fuzz) > 1) $angle_to = 1;
372
+				fill_arc($image, $x, $y, $size, $angle_from * 360, $angle_to * 360, $col_black, $col_red);
373
+				if (($angle_to - $angle_from) > 0.05) {
374
+					array_push($string_placement, array($angle_from, $angle_to));
375 375
 				}
376 376
 			}
377 377
 		}
378 378
 		foreach ($string_placement as $angle) {
379
-			text_arc($image,$x,$y,$size,$angle[0]*360,$angle[1]*360,$col_black,bsize($s*($angle[1]-$angle[0])));
379
+			text_arc($image, $x, $y, $size, $angle[0] * 360, $angle[1] * 360, $col_black, bsize($s * ($angle[1] - $angle[0])));
380 380
 		}
381 381
 		break;
382 382
 
383 383
 	case 2:
384
-		$s=$cache['nhits']+$cache['nmisses'];
385
-		$a=$cache['nhits'];
384
+		$s = $cache['nhits'] + $cache['nmisses'];
385
+		$a = $cache['nhits'];
386 386
 
387
-		fill_box($image, 30,$size,50,$s ? (-$a*($size-21)/$s) : 0,$col_black,$col_green,sprintf("%.1f%%",$s ? $cache['nhits']*100/$s : 0));
388
-		fill_box($image,130,$size,50,$s ? -max(4,($s-$a)*($size-21)/$s) : 0,$col_black,$col_red,sprintf("%.1f%%",$s ? $cache['nmisses']*100/$s : 0));
387
+		fill_box($image, 30, $size, 50, $s ? (-$a * ($size - 21) / $s) : 0, $col_black, $col_green, sprintf("%.1f%%", $s ? $cache['nhits'] * 100 / $s : 0));
388
+		fill_box($image, 130, $size, 50, $s ? -max(4, ($s - $a) * ($size - 21) / $s) : 0, $col_black, $col_red, sprintf("%.1f%%", $s ? $cache['nmisses'] * 100 / $s : 0));
389 389
 		break;
390 390
 
391 391
 	case 3:
392
-		$s=$mem['num_seg']*$mem['seg_size'];
393
-		$a=$mem['avail_mem'];
394
-		$x=130;
395
-		$y=1;
396
-		$j=1;
392
+		$s = $mem['num_seg'] * $mem['seg_size'];
393
+		$a = $mem['avail_mem'];
394
+		$x = 130;
395
+		$y = 1;
396
+		$j = 1;
397 397
 
398 398
 		// This block of code creates the bar chart.  It is a lot more complex than you
399 399
 		// would expect because we try to visualize any memory fragmentation as well.
400
-		for($i=0; $i<$mem['num_seg']; $i++) {
400
+		for ($i = 0; $i < $mem['num_seg']; $i++) {
401 401
 			$ptr = 0;
402 402
 			$free = $mem['block_lists'][$i];
403 403
 			uasort($free, 'block_sort');
404
-			foreach($free as $block) {
405
-				if($block['offset']!=$ptr) {       // Used block
406
-					$h=(GRAPH_SIZE-5)*($block['offset']-$ptr)/$s;
407
-					if ($h>0) {
404
+			foreach ($free as $block) {
405
+				if ($block['offset'] != $ptr) {       // Used block
406
+					$h = (GRAPH_SIZE - 5) * ($block['offset'] - $ptr) / $s;
407
+					if ($h > 0) {
408 408
                                                 $j++;
409
-						if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($block['offset']-$ptr),$j);
410
-                                                else fill_box($image,$x,$y,50,$h,$col_black,$col_red);
409
+						if ($j < 75) fill_box($image, $x, $y, 50, $h, $col_black, $col_red, bsize($block['offset'] - $ptr), $j);
410
+                                                else fill_box($image, $x, $y, 50, $h, $col_black, $col_red);
411 411
                                         }
412
-					$y+=$h;
412
+					$y += $h;
413 413
 				}
414
-				$h=(GRAPH_SIZE-5)*($block['size'])/$s;
415
-				if ($h>0) {
414
+				$h = (GRAPH_SIZE - 5) * ($block['size']) / $s;
415
+				if ($h > 0) {
416 416
                                         $j++;
417
-					if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_green,bsize($block['size']),$j);
418
-					else fill_box($image,$x,$y,50,$h,$col_black,$col_green);
417
+					if ($j < 75) fill_box($image, $x, $y, 50, $h, $col_black, $col_green, bsize($block['size']), $j);
418
+					else fill_box($image, $x, $y, 50, $h, $col_black, $col_green);
419 419
                                 }
420
-				$y+=$h;
421
-				$ptr = $block['offset']+$block['size'];
420
+				$y += $h;
421
+				$ptr = $block['offset'] + $block['size'];
422 422
 			}
423 423
 			if ($ptr < $mem['seg_size']) { // memory at the end
424
-				$h = (GRAPH_SIZE-5) * ($mem['seg_size'] - $ptr) / $s;
424
+				$h = (GRAPH_SIZE - 5) * ($mem['seg_size'] - $ptr) / $s;
425 425
 				if ($h > 0) {
426
-					fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($mem['seg_size']-$ptr),$j++);
426
+					fill_box($image, $x, $y, 50, $h, $col_black, $col_red, bsize($mem['seg_size'] - $ptr), $j++);
427 427
 				}
428 428
 			}
429 429
 		}
430 430
 		break;
431 431
 
432 432
 		case 4:
433
-			$s=$cache['nhits']+$cache['nmisses'];
434
-			$a=$cache['nhits'];
433
+			$s = $cache['nhits'] + $cache['nmisses'];
434
+			$a = $cache['nhits'];
435 435
 
436
-			fill_box($image, 30,$size,50,$s ? -$a*($size-21)/$s : 0,$col_black,$col_green,sprintf("%.1f%%", $s ? $cache['nhits']*100/$s : 0));
437
-			fill_box($image,130,$size,50,$s ? -max(4,($s-$a)*($size-21)/$s) : 0,$col_black,$col_red,sprintf("%.1f%%", $s ? $cache['nmisses']*100/$s : 0));
436
+			fill_box($image, 30, $size, 50, $s ? -$a * ($size - 21) / $s : 0, $col_black, $col_green, sprintf("%.1f%%", $s ? $cache['nhits'] * 100 / $s : 0));
437
+			fill_box($image, 130, $size, 50, $s ? -max(4, ($s - $a) * ($size - 21) / $s) : 0, $col_black, $col_red, sprintf("%.1f%%", $s ? $cache['nmisses'] * 100 / $s : 0));
438 438
 		break;
439 439
 	}
440 440
 
@@ -446,28 +446,28 @@  discard block
 block discarded – undo
446 446
 // pretty printer for byte values
447 447
 //
448 448
 function bsize($s) {
449
-	foreach (array('','K','M','G') as $i => $k) {
449
+	foreach (array('', 'K', 'M', 'G') as $i => $k) {
450 450
 		if ($s < 1024) break;
451
-		$s/=1024;
451
+		$s /= 1024;
452 452
 	}
453
-	return sprintf("%5.1f %sBytes",$s,$k);
453
+	return sprintf("%5.1f %sBytes", $s, $k);
454 454
 }
455 455
 
456 456
 // sortable table header in "scripts for this host" view
457
-function sortheader($key,$name,$extra='') {
457
+function sortheader($key, $name, $extra = '') {
458 458
 	global $MYREQUEST, $MY_SELF_WO_SORT;
459 459
 
460
-	if ($MYREQUEST['SORT1']==$key) {
461
-		$MYREQUEST['SORT2'] = $MYREQUEST['SORT2']=='A' ? 'D' : 'A';
460
+	if ($MYREQUEST['SORT1'] == $key) {
461
+		$MYREQUEST['SORT2'] = $MYREQUEST['SORT2'] == 'A' ? 'D' : 'A';
462 462
 	}
463 463
 	return "<a class=sortable href=\"$MY_SELF_WO_SORT$extra&SORT1=$key&SORT2=".$MYREQUEST['SORT2']."\">$name</a>";
464 464
 
465 465
 }
466 466
 
467 467
 // create menu entry
468
-function menu_entry($ob,$title) {
469
-	global $MYREQUEST,$MY_SELF;
470
-	if ($MYREQUEST['OB']!=$ob) {
468
+function menu_entry($ob, $title) {
469
+	global $MYREQUEST, $MY_SELF;
470
+	if ($MYREQUEST['OB'] != $ob) {
471 471
 		return "<li><a href=\"$MY_SELF&OB=$ob\">$title</a></li>";
472 472
 	} else if (empty($MYREQUEST['SH'])) {
473 473
 		return "<li><span class=active>$title</span></li>";
@@ -476,14 +476,14 @@  discard block
 block discarded – undo
476 476
 	}
477 477
 }
478 478
 
479
-function put_login_link($s="Login")
479
+function put_login_link($s = "Login")
480 480
 {
481
-	global $MY_SELF,$MYREQUEST,$AUTHENTICATED;
481
+	global $MY_SELF, $MYREQUEST, $AUTHENTICATED;
482 482
 	// needs ADMIN_PASSWORD to be changed!
483 483
 	//
484 484
 	if (!USE_AUTHENTICATION) {
485 485
 		return;
486
-	} else if (ADMIN_PASSWORD=='password')
486
+	} else if (ADMIN_PASSWORD == 'password')
487 487
 	{
488 488
 		print <<<EOB
489 489
 			<a href="#" onClick="javascript:alert('You need to set a password at the top of apc.php before this will work!');return false";>$s</a>
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 		print <<<EOB
493 493
 			'{$_SERVER['PHP_AUTH_USER']}'&nbsp;logged&nbsp;in!
494 494
 EOB;
495
-	} else{
495
+	} else {
496 496
 		print <<<EOB
497 497
 			<a href="$MY_SELF&LO=1&OB={$MYREQUEST['OB']}">$s</a>
498 498
 EOB;
@@ -729,9 +729,9 @@  discard block
 block discarded – undo
729 729
 	<li><a href="$MY_SELF&OB={$MYREQUEST['OB']}&SH={$MYREQUEST['SH']}">Refresh Data</a></li>
730 730
 EOB;
731 731
 echo
732
-	menu_entry(OB_HOST_STATS,'View Host Stats'),
733
-	menu_entry(OB_USER_CACHE,'User Cache Entries'),
734
-	menu_entry(OB_VERSION_CHECK,'Version Check');
732
+	menu_entry(OB_HOST_STATS, 'View Host Stats'),
733
+	menu_entry(OB_USER_CACHE, 'User Cache Entries'),
734
+	menu_entry(OB_VERSION_CHECK, 'Version Check');
735 735
 
736 736
 if ($AUTHENTICATED) {
737 737
 	echo <<<EOB
@@ -755,19 +755,19 @@  discard block
 block discarded – undo
755 755
 // Host Stats
756 756
 // -----------------------------------------------
757 757
 case OB_HOST_STATS:
758
-	$mem_size = $mem['num_seg']*$mem['seg_size'];
759
-	$mem_avail= $mem['avail_mem'];
760
-	$mem_used = $mem_size-$mem_avail;
758
+	$mem_size = $mem['num_seg'] * $mem['seg_size'];
759
+	$mem_avail = $mem['avail_mem'];
760
+	$mem_used = $mem_size - $mem_avail;
761 761
 	$seg_size = bsize($mem['seg_size']);
762
-	$req_rate_user = sprintf("%.2f", $cache['nhits'] ? (($cache['nhits']+$cache['nmisses'])/($time-$cache['stime'])) : 0);
763
-	$hit_rate_user = sprintf("%.2f", $cache['nhits'] ? (($cache['nhits'])/($time-$cache['stime'])) : 0);
764
-	$miss_rate_user = sprintf("%.2f", $cache['nmisses'] ? (($cache['nmisses'])/($time-$cache['stime'])) : 0);
765
-	$insert_rate_user = sprintf("%.2f", $cache['ninserts'] ? (($cache['ninserts'])/($time-$cache['stime'])) : 0);
762
+	$req_rate_user = sprintf("%.2f", $cache['nhits'] ? (($cache['nhits'] + $cache['nmisses']) / ($time - $cache['stime'])) : 0);
763
+	$hit_rate_user = sprintf("%.2f", $cache['nhits'] ? (($cache['nhits']) / ($time - $cache['stime'])) : 0);
764
+	$miss_rate_user = sprintf("%.2f", $cache['nmisses'] ? (($cache['nmisses']) / ($time - $cache['stime'])) : 0);
765
+	$insert_rate_user = sprintf("%.2f", $cache['ninserts'] ? (($cache['ninserts']) / ($time - $cache['stime'])) : 0);
766 766
 	$apcversion = phpversion('apcu');
767 767
 	$phpversion = phpversion();
768 768
 	$number_vars = $cache['nentries'];
769 769
     $size_vars = bsize($cache['mem_size']);
770
-	$i=0;
770
+	$i = 0;
771 771
 	echo <<< EOB
772 772
 		<div class="info div1"><h2>General Cache Information</h2>
773 773
 		<table cellspacing=0><tbody>
@@ -775,9 +775,9 @@  discard block
 block discarded – undo
775 775
 		<tr class=tr-1><td class=td-0>PHP Version</td><td>$phpversion</td></tr>
776 776
 EOB;
777 777
 
778
-	if(!empty($_SERVER['SERVER_NAME']))
778
+	if (!empty($_SERVER['SERVER_NAME']))
779 779
 		echo "<tr class=tr-0><td class=td-0>APCu Host</td><td>{$_SERVER['SERVER_NAME']} $host</td></tr>\n";
780
-	if(!empty($_SERVER['SERVER_SOFTWARE']))
780
+	if (!empty($_SERVER['SERVER_SOFTWARE']))
781 781
 		echo "<tr class=tr-1><td class=td-0>Server Software</td><td>{$_SERVER['SERVER_SOFTWARE']}</td></tr>\n";
782 782
 
783 783
 	echo <<<EOB
@@ -785,9 +785,9 @@  discard block
 block discarded – undo
785 785
     <br/> ({$cache['memory_type']} memory)
786 786
     </td></tr>
787 787
 EOB;
788
-	echo   '<tr class=tr-1><td class=td-0>Start Time</td><td>',date(DATE_FORMAT,$cache['stime']),'</td></tr>';
789
-	echo   '<tr class=tr-0><td class=td-0>Uptime</td><td>',duration($cache['stime']),'</td></tr>';
790
-	echo   '<tr class=tr-1><td class=td-0>File Upload Support</td><td>',$cache['file_upload_progress'],'</td></tr>';
788
+	echo   '<tr class=tr-1><td class=td-0>Start Time</td><td>', date(DATE_FORMAT, $cache['stime']), '</td></tr>';
789
+	echo   '<tr class=tr-0><td class=td-0>Uptime</td><td>', duration($cache['stime']), '</td></tr>';
790
+	echo   '<tr class=tr-1><td class=td-0>File Upload Support</td><td>', $cache['file_upload_progress'], '</td></tr>';
791 791
 	echo <<<EOB
792 792
 		</tbody></table>
793 793
 		</div>
@@ -812,11 +812,11 @@  discard block
 block discarded – undo
812 812
 
813 813
 	$j = 0;
814 814
 	foreach (ini_get_all('apcu') as $k => $v) {
815
-		echo "<tr class=tr-$j><td class=td-0>",$k,"</td><td>",str_replace(',',',<br />',$v['local_value']),"</td></tr>\n";
815
+		echo "<tr class=tr-$j><td class=td-0>", $k, "</td><td>", str_replace(',', ',<br />', $v['local_value']), "</td></tr>\n";
816 816
 		$j = 1 - $j;
817 817
 	}
818 818
 
819
-	if($mem['num_seg']>1 || $mem['num_seg']==1 && count($mem['block_lists'][0])>1)
819
+	if ($mem['num_seg'] > 1 || $mem['num_seg'] == 1 && count($mem['block_lists'][0]) > 1)
820 820
 		$mem_note = "Memory Usage<br /><font size=-2>(multiple slices indicate fragments)</font>";
821 821
 	else
822 822
 		$mem_note = "Memory Usage";
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
 		<div class="graph div3"><h2>Host Status Diagrams</h2>
829 829
 		<table cellspacing=0><tbody>
830 830
 EOB;
831
-	$size='width='.(GRAPH_SIZE+50).' height='.(GRAPH_SIZE+10);
831
+	$size = 'width='.(GRAPH_SIZE + 50).' height='.(GRAPH_SIZE + 10);
832 832
 echo <<<EOB
833 833
 		<tr>
834 834
 		<td class=td-0>$mem_note</td>
@@ -843,12 +843,12 @@  discard block
 block discarded – undo
843 843
 			  "<td class=td-1><img alt=\"\" $size src=\"$PHP_SELF?IMG=2&$time\"></td></tr>\n"
844 844
 			: "",
845 845
 		'<tr>',
846
-		'<td class=td-0><span class="green box">&nbsp;</span>Free: ',bsize($mem_avail).sprintf(" (%.1f%%)",$mem_avail*100/$mem_size),"</td>\n",
847
-		'<td class=td-1><span class="green box">&nbsp;</span>Hits: ',$cache['nhits'].@sprintf(" (%.1f%%)",$cache['nhits']*100/($cache['nhits']+$cache['nmisses'])),"</td>\n",
846
+		'<td class=td-0><span class="green box">&nbsp;</span>Free: ', bsize($mem_avail).sprintf(" (%.1f%%)", $mem_avail * 100 / $mem_size), "</td>\n",
847
+		'<td class=td-1><span class="green box">&nbsp;</span>Hits: ', $cache['nhits'].@sprintf(" (%.1f%%)", $cache['nhits'] * 100 / ($cache['nhits'] + $cache['nmisses'])), "</td>\n",
848 848
 		'</tr>',
849 849
 		'<tr>',
850
-		'<td class=td-0><span class="red box">&nbsp;</span>Used: ',bsize($mem_used ).sprintf(" (%.1f%%)",$mem_used *100/$mem_size),"</td>\n",
851
-		'<td class=td-1><span class="red box">&nbsp;</span>Misses: ',$cache['nmisses'].@sprintf(" (%.1f%%)",$cache['nmisses']*100/($cache['nhits']+$cache['nmisses'])),"</td>\n";
850
+		'<td class=td-0><span class="red box">&nbsp;</span>Used: ', bsize($mem_used).sprintf(" (%.1f%%)", $mem_used * 100 / $mem_size), "</td>\n",
851
+		'<td class=td-1><span class="red box">&nbsp;</span>Misses: ', $cache['nmisses'].@sprintf(" (%.1f%%)", $cache['nmisses'] * 100 / ($cache['nhits'] + $cache['nmisses'])), "</td>\n";
852 852
 	echo <<< EOB
853 853
 		</tr>
854 854
 		</tbody></table>
@@ -862,28 +862,28 @@  discard block
 block discarded – undo
862 862
 
863 863
 	// Fragementation: (freeseg - 1) / total_seg
864 864
 	$nseg = $freeseg = $fragsize = $freetotal = 0;
865
-	for($i=0; $i<$mem['num_seg']; $i++) {
865
+	for ($i = 0; $i < $mem['num_seg']; $i++) {
866 866
 		$ptr = 0;
867
-		foreach($mem['block_lists'][$i] as $block) {
867
+		foreach ($mem['block_lists'][$i] as $block) {
868 868
 			if ($block['offset'] != $ptr) {
869 869
 				++$nseg;
870 870
 			}
871 871
 			$ptr = $block['offset'] + $block['size'];
872 872
                         /* Only consider blocks <5M for the fragmentation % */
873
-                        if($block['size']<(5*1024*1024)) $fragsize+=$block['size'];
874
-                        $freetotal+=$block['size'];
873
+                        if ($block['size'] < (5 * 1024 * 1024)) $fragsize += $block['size'];
874
+                        $freetotal += $block['size'];
875 875
 		}
876 876
 		$freeseg += count($mem['block_lists'][$i]);
877 877
 	}
878 878
 
879 879
 	if ($freeseg > 1) {
880
-		$frag = sprintf("%.2f%% (%s out of %s in %d fragments)", ($fragsize/$freetotal)*100,bsize($fragsize),bsize($freetotal),$freeseg);
880
+		$frag = sprintf("%.2f%% (%s out of %s in %d fragments)", ($fragsize / $freetotal) * 100, bsize($fragsize), bsize($freetotal), $freeseg);
881 881
 	} else {
882 882
 		$frag = "0%";
883 883
 	}
884 884
 
885 885
 	if (graphics_avail()) {
886
-		$size='width='.(2*GRAPH_SIZE+150).' height='.(GRAPH_SIZE+10);
886
+		$size = 'width='.(2 * GRAPH_SIZE + 150).' height='.(GRAPH_SIZE + 10);
887 887
 		echo <<<EOB
888 888
 			<img alt="" $size src="$PHP_SELF?IMG=3&$time">
889 889
 EOB;
@@ -893,10 +893,10 @@  discard block
 block discarded – undo
893 893
 		</td>
894 894
 		</tr>
895 895
 EOB;
896
-        if(isset($mem['adist'])) {
897
-          foreach($mem['adist'] as $i=>$v) {
898
-            $cur = pow(2,$i); $nxt = pow(2,$i+1)-1;
899
-            if($i==0) $range = "1";
896
+        if (isset($mem['adist'])) {
897
+          foreach ($mem['adist'] as $i=>$v) {
898
+            $cur = pow(2, $i); $nxt = pow(2, $i + 1) - 1;
899
+            if ($i == 0) $range = "1";
900 900
             else $range = "$cur - $nxt";
901 901
             echo "<tr><th align=right>$range</th><td align=right>$v</td></tr>\n";
902 902
           }
@@ -919,47 +919,47 @@  discard block
 block discarded – undo
919 919
 		echo '</div>';
920 920
 		break;
921 921
 	}
922
-	$fieldname='key';
923
-	$fieldheading='User Entry Label';
924
-	$fieldkey='key';
922
+	$fieldname = 'key';
923
+	$fieldheading = 'User Entry Label';
924
+	$fieldkey = 'key';
925 925
 
926
-	$cols=6;
926
+	$cols = 6;
927 927
 	echo <<<EOB
928 928
 		<div class=sorting><form>Scope:
929 929
 		<input type=hidden name=OB value={$MYREQUEST['OB']}>
930 930
 		<select name=SCOPE>
931 931
 EOB;
932 932
 	echo
933
-		"<option value=A",$MYREQUEST['SCOPE']=='A' ? " selected":"",">Active</option>",
934
-		"<option value=D",$MYREQUEST['SCOPE']=='D' ? " selected":"",">Deleted</option>",
933
+		"<option value=A", $MYREQUEST['SCOPE'] == 'A' ? " selected" : "", ">Active</option>",
934
+		"<option value=D", $MYREQUEST['SCOPE'] == 'D' ? " selected" : "", ">Deleted</option>",
935 935
 		"</select>",
936 936
 		", Sorting:<select name=SORT1>",
937
-		"<option value=H",$MYREQUEST['SORT1']=='H' ? " selected":"",">Hits</option>",
938
-		"<option value=Z",$MYREQUEST['SORT1']=='Z' ? " selected":"",">Size</option>",
939
-		"<option value=S",$MYREQUEST['SORT1']=='S' ? " selected":"",">$fieldheading</option>",
940
-		"<option value=A",$MYREQUEST['SORT1']=='A' ? " selected":"",">Last accessed</option>",
941
-		"<option value=M",$MYREQUEST['SORT1']=='M' ? " selected":"",">Last modified</option>",
942
-		"<option value=C",$MYREQUEST['SORT1']=='C' ? " selected":"",">Created at</option>",
943
-		"<option value=D",$MYREQUEST['SORT1']=='D' ? " selected":"",">Deleted at</option>";
944
-	if($fieldname=='info') echo
945
-		"<option value=D",$MYREQUEST['SORT1']=='T' ? " selected":"",">Timeout</option>";
937
+		"<option value=H", $MYREQUEST['SORT1'] == 'H' ? " selected" : "", ">Hits</option>",
938
+		"<option value=Z", $MYREQUEST['SORT1'] == 'Z' ? " selected" : "", ">Size</option>",
939
+		"<option value=S", $MYREQUEST['SORT1'] == 'S' ? " selected" : "", ">$fieldheading</option>",
940
+		"<option value=A", $MYREQUEST['SORT1'] == 'A' ? " selected" : "", ">Last accessed</option>",
941
+		"<option value=M", $MYREQUEST['SORT1'] == 'M' ? " selected" : "", ">Last modified</option>",
942
+		"<option value=C", $MYREQUEST['SORT1'] == 'C' ? " selected" : "", ">Created at</option>",
943
+		"<option value=D", $MYREQUEST['SORT1'] == 'D' ? " selected" : "", ">Deleted at</option>";
944
+	if ($fieldname == 'info') echo
945
+		"<option value=D", $MYREQUEST['SORT1'] == 'T' ? " selected" : "", ">Timeout</option>";
946 946
 	echo
947 947
 		'</select>',
948 948
 		'<select name=SORT2>',
949
-		'<option value=D',$MYREQUEST['SORT2']=='D' ? ' selected':'','>DESC</option>',
950
-		'<option value=A',$MYREQUEST['SORT2']=='A' ? ' selected':'','>ASC</option>',
949
+		'<option value=D', $MYREQUEST['SORT2'] == 'D' ? ' selected' : '', '>DESC</option>',
950
+		'<option value=A', $MYREQUEST['SORT2'] == 'A' ? ' selected' : '', '>ASC</option>',
951 951
 		'</select>',
952 952
 		'<select name=COUNT onChange="form.submit()">',
953
-		'<option value=10 ',$MYREQUEST['COUNT']=='10' ? ' selected':'','>Top 10</option>',
954
-		'<option value=20 ',$MYREQUEST['COUNT']=='20' ? ' selected':'','>Top 20</option>',
955
-		'<option value=50 ',$MYREQUEST['COUNT']=='50' ? ' selected':'','>Top 50</option>',
956
-		'<option value=100',$MYREQUEST['COUNT']=='100'? ' selected':'','>Top 100</option>',
957
-		'<option value=150',$MYREQUEST['COUNT']=='150'? ' selected':'','>Top 150</option>',
958
-		'<option value=200',$MYREQUEST['COUNT']=='200'? ' selected':'','>Top 200</option>',
959
-		'<option value=500',$MYREQUEST['COUNT']=='500'? ' selected':'','>Top 500</option>',
960
-		'<option value=0  ',$MYREQUEST['COUNT']=='0'  ? ' selected':'','>All</option>',
953
+		'<option value=10 ', $MYREQUEST['COUNT'] == '10' ? ' selected' : '', '>Top 10</option>',
954
+		'<option value=20 ', $MYREQUEST['COUNT'] == '20' ? ' selected' : '', '>Top 20</option>',
955
+		'<option value=50 ', $MYREQUEST['COUNT'] == '50' ? ' selected' : '', '>Top 50</option>',
956
+		'<option value=100', $MYREQUEST['COUNT'] == '100' ? ' selected' : '', '>Top 100</option>',
957
+		'<option value=150', $MYREQUEST['COUNT'] == '150' ? ' selected' : '', '>Top 150</option>',
958
+		'<option value=200', $MYREQUEST['COUNT'] == '200' ? ' selected' : '', '>Top 200</option>',
959
+		'<option value=500', $MYREQUEST['COUNT'] == '500' ? ' selected' : '', '>Top 500</option>',
960
+		'<option value=0  ', $MYREQUEST['COUNT'] == '0' ? ' selected' : '', '>All</option>',
961 961
 		'</select>',
962
-    '&nbsp; Search: <input name=SEARCH value="',$MYREQUEST['SEARCH'],'" type=text size=25/>',
962
+    '&nbsp; Search: <input name=SEARCH value="', $MYREQUEST['SEARCH'], '" type=text size=25/>',
963 963
 		'&nbsp;<input type=submit value="GO!">',
964 964
 		'</form></div>';
965 965
 
@@ -976,39 +976,39 @@  discard block
 block discarded – undo
976 976
   echo
977 977
 		'<div class="info"><table cellspacing=0><tbody>',
978 978
 		'<tr>',
979
-		'<th>',sortheader('S',$fieldheading,  "&OB=".$MYREQUEST['OB']),'</th>',
980
-		'<th>',sortheader('H','Hits',         "&OB=".$MYREQUEST['OB']),'</th>',
981
-		'<th>',sortheader('Z','Size',         "&OB=".$MYREQUEST['OB']),'</th>',
982
-		'<th>',sortheader('A','Last accessed',"&OB=".$MYREQUEST['OB']),'</th>',
983
-		'<th>',sortheader('M','Last modified',"&OB=".$MYREQUEST['OB']),'</th>',
984
-		'<th>',sortheader('C','Created at',   "&OB=".$MYREQUEST['OB']),'</th>';
985
-
986
-	if($fieldname=='info') {
987
-		$cols+=2;
988
-		 echo '<th>',sortheader('T','Timeout',"&OB=".$MYREQUEST['OB']),'</th>';
979
+		'<th>', sortheader('S', $fieldheading, "&OB=".$MYREQUEST['OB']), '</th>',
980
+		'<th>', sortheader('H', 'Hits', "&OB=".$MYREQUEST['OB']), '</th>',
981
+		'<th>', sortheader('Z', 'Size', "&OB=".$MYREQUEST['OB']), '</th>',
982
+		'<th>', sortheader('A', 'Last accessed', "&OB=".$MYREQUEST['OB']), '</th>',
983
+		'<th>', sortheader('M', 'Last modified', "&OB=".$MYREQUEST['OB']), '</th>',
984
+		'<th>', sortheader('C', 'Created at', "&OB=".$MYREQUEST['OB']), '</th>';
985
+
986
+	if ($fieldname == 'info') {
987
+		$cols += 2;
988
+		 echo '<th>', sortheader('T', 'Timeout', "&OB=".$MYREQUEST['OB']), '</th>';
989 989
 	}
990
-	echo '<th>',sortheader('D','Deleted at',"&OB=".$MYREQUEST['OB']),'</th></tr>';
990
+	echo '<th>', sortheader('D', 'Deleted at', "&OB=".$MYREQUEST['OB']), '</th></tr>';
991 991
 
992 992
 	// builds list with alpha numeric sortable keys
993 993
 	//
994 994
 	$list = array();
995 995
 
996
-	foreach($cache[$scope_list[$MYREQUEST['SCOPE']]] as $i => $entry) {
997
-		switch($MYREQUEST['SORT1']) {
998
-			case 'A': $k=sprintf('%015d-',$entry['atime']);  	    break;
999
-			case 'H': $k=sprintf('%015d-',$entry['nhits']); 		break;
1000
-			case 'Z': $k=sprintf('%015d-',$entry['mem_size']); 		break;
1001
-			case 'M': $k=sprintf('%015d-',$entry['mtime']);			break;
1002
-			case 'C': $k=sprintf('%015d-',$entry['ctime']);	        break;
1003
-			case 'T': $k=sprintf('%015d-',$entry['ttl']);			break;
1004
-			case 'D': $k=sprintf('%015d-',$entry['dtime']);      	break;
1005
-			case 'S': $k=$entry["key"];								break;
996
+	foreach ($cache[$scope_list[$MYREQUEST['SCOPE']]] as $i => $entry) {
997
+		switch ($MYREQUEST['SORT1']) {
998
+			case 'A': $k = sprintf('%015d-', $entry['atime']); break;
999
+			case 'H': $k = sprintf('%015d-', $entry['nhits']); break;
1000
+			case 'Z': $k = sprintf('%015d-', $entry['mem_size']); break;
1001
+			case 'M': $k = sprintf('%015d-', $entry['mtime']); break;
1002
+			case 'C': $k = sprintf('%015d-', $entry['ctime']); break;
1003
+			case 'T': $k = sprintf('%015d-', $entry['ttl']); break;
1004
+			case 'D': $k = sprintf('%015d-', $entry['dtime']); break;
1005
+			case 'S': $k = $entry["key"]; break;
1006 1006
 		}
1007 1007
 		if (!$AUTHENTICATED) {
1008 1008
 			// hide all path entries if not logged in
1009
-			$list[$k.$entry[$fieldname]]=preg_replace('/^.*(\\/|\\\\)/','*hidden*/',$entry);
1009
+			$list[$k.$entry[$fieldname]] = preg_replace('/^.*(\\/|\\\\)/', '*hidden*/', $entry);
1010 1010
 		} else {
1011
-			$list[$k.$entry[$fieldname]]=$entry;
1011
+			$list[$k.$entry[$fieldname]] = $entry;
1012 1012
 		}
1013 1013
 	}
1014 1014
 
@@ -1016,34 +1016,34 @@  discard block
 block discarded – undo
1016 1016
 		// sort list
1017 1017
 		//
1018 1018
 		switch ($MYREQUEST['SORT2']) {
1019
-			case "A":	krsort($list);	break;
1020
-			case "D":	ksort($list);	break;
1019
+			case "A":	krsort($list); break;
1020
+			case "D":	ksort($list); break;
1021 1021
 		}
1022 1022
 
1023 1023
 		// output list
1024
-		$i=0;
1025
-		foreach($list as $k => $entry) {
1026
-      if(!$MYREQUEST['SEARCH'] || preg_match($MYREQUEST['SEARCH'], $entry[$fieldname]) != 0) {
1027
-		$sh=md5($entry["key"]);
1028
-        $field_value = htmlentities(strip_tags($entry[$fieldname],''), ENT_QUOTES, 'UTF-8');
1024
+		$i = 0;
1025
+		foreach ($list as $k => $entry) {
1026
+      if (!$MYREQUEST['SEARCH'] || preg_match($MYREQUEST['SEARCH'], $entry[$fieldname]) != 0) {
1027
+		$sh = md5($entry["key"]);
1028
+        $field_value = htmlentities(strip_tags($entry[$fieldname], ''), ENT_QUOTES, 'UTF-8');
1029 1029
         echo
1030
-          '<tr class=tr-',$i%2,'>',
1031
-          "<td class=td-0><a href=\"$MY_SELF&OB=",$MYREQUEST['OB'],"&SH=",$sh,"\">",$field_value,'</a></td>',
1032
-          '<td class="td-n center">',$entry['nhits'],'</td>',
1033
-          '<td class="td-n right">',$entry['mem_size'],'</td>',
1034
-          '<td class="td-n center">',date(DATE_FORMAT,$entry['atime']),'</td>',
1035
-          '<td class="td-n center">',date(DATE_FORMAT,$entry['mtime']),'</td>',
1036
-          '<td class="td-n center">',date(DATE_FORMAT,$entry['ctime']),'</td>';
1037
-
1038
-        if($fieldname=='info') {
1039
-          if($entry['ttl'])
1030
+          '<tr class=tr-', $i % 2, '>',
1031
+          "<td class=td-0><a href=\"$MY_SELF&OB=", $MYREQUEST['OB'], "&SH=", $sh, "\">", $field_value, '</a></td>',
1032
+          '<td class="td-n center">', $entry['nhits'], '</td>',
1033
+          '<td class="td-n right">', $entry['mem_size'], '</td>',
1034
+          '<td class="td-n center">', date(DATE_FORMAT, $entry['atime']), '</td>',
1035
+          '<td class="td-n center">', date(DATE_FORMAT, $entry['mtime']), '</td>',
1036
+          '<td class="td-n center">', date(DATE_FORMAT, $entry['ctime']), '</td>';
1037
+
1038
+        if ($fieldname == 'info') {
1039
+          if ($entry['ttl'])
1040 1040
             echo '<td class="td-n center">'.$entry['ttl'].' seconds</td>';
1041 1041
           else
1042 1042
             echo '<td class="td-n center">None</td>';
1043 1043
         }
1044 1044
         if ($entry['dtime']) {
1045 1045
 
1046
-          echo '<td class="td-last center">', date(DATE_FORMAT,$entry['dtime']), '</td>';
1046
+          echo '<td class="td-last center">', date(DATE_FORMAT, $entry['dtime']), '</td>';
1047 1047
         } else if ($MYREQUEST['OB'] == OB_USER_CACHE) {
1048 1048
 
1049 1049
           echo '<td class="td-last center">';
@@ -1065,14 +1065,14 @@  discard block
 block discarded – undo
1065 1065
 		}
1066 1066
 
1067 1067
 	} else {
1068
-		echo '<tr class=tr-0><td class="center" colspan=',$cols,'><i>No data</i></td></tr>';
1068
+		echo '<tr class=tr-0><td class="center" colspan=', $cols, '><i>No data</i></td></tr>';
1069 1069
 	}
1070 1070
 	echo <<< EOB
1071 1071
 		</tbody></table>
1072 1072
 EOB;
1073 1073
 
1074 1074
 	if ($list && $i < count($list)) {
1075
-		echo "<a href=\"$MY_SELF&OB=",$MYREQUEST['OB'],"&COUNT=0\"><i>",count($list)-$i,' more available...</i></a>';
1075
+		echo "<a href=\"$MY_SELF&OB=", $MYREQUEST['OB'], "&COUNT=0\"><i>", count($list) - $i, ' more available...</i></a>';
1076 1076
 	}
1077 1077
 
1078 1078
 	echo <<< EOB
@@ -1092,7 +1092,7 @@  discard block
 block discarded – undo
1092 1092
 		</tr>
1093 1093
 EOB;
1094 1094
   if (defined('PROXY')) {
1095
-    $ctxt = stream_context_create( array( 'http' => array( 'proxy' => PROXY, 'request_fulluri' => True ) ) );
1095
+    $ctxt = stream_context_create(array('http' => array('proxy' => PROXY, 'request_fulluri' => True)));
1096 1096
     $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss", False, $ctxt);
1097 1097
   } else {
1098 1098
     $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss");
Please login to merge, or discard this patch.
var/www/admin/memcache/index.php 2 patches
Doc Comments   +10 added lines patch added patch discarded remove patch
@@ -57,6 +57,9 @@  discard block
 block discarded – undo
57 57
 	}
58 58
 }
59 59
 
60
+/**
61
+ * @param string $command
62
+ */
60 63
 function sendMemcacheCommands($command){
61 64
     global $MEMCACHE_SERVERS;
62 65
 	$result = array();
@@ -94,6 +97,9 @@  discard block
 block discarded – undo
94 97
     fclose($s);
95 98
     return parseMemcacheResults($buf);
96 99
 }
100
+/**
101
+ * @param string $str
102
+ */
97 103
 function parseMemcacheResults($str){
98 104
     
99 105
 	$res = array();
@@ -285,6 +291,10 @@  discard block
 block discarded – undo
285 291
 }
286 292
 
287 293
 // create menu entry
294
+/**
295
+ * @param integer $ob
296
+ * @param string $title
297
+ */
288 298
 function menu_entry($ob,$title) {
289 299
 	global $PHP_SELF;
290 300
 	if ($ob==$_GET['op']){
Please login to merge, or discard this patch.
Spacing   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  discard block
 block discarded – undo
17 17
   +----------------------------------------------------------------------+
18 18
 */
19 19
 
20
-$VERSION='$Id$';
20
+$VERSION = '$Id$';
21 21
 
22
-define('ADMIN_USERNAME',''); 	// Admin Username
23
-define('ADMIN_PASSWORD','');  	// Admin Password
24
-define('DATE_FORMAT','Y/m/d H:i:s');
25
-define('GRAPH_SIZE',200);
26
-define('MAX_ITEM_DUMP',50);
22
+define('ADMIN_USERNAME', ''); // Admin Username
23
+define('ADMIN_PASSWORD', ''); // Admin Password
24
+define('DATE_FORMAT', 'Y/m/d H:i:s');
25
+define('GRAPH_SIZE', 200);
26
+define('MAX_ITEM_DUMP', 50);
27 27
 
28 28
 $MEMCACHE_SERVERS[] = 'localhost:11211'; // add more as an array
29 29
 
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
 
48 48
 ///////////MEMCACHE FUNCTIONS /////////////////////////////////////////////////////////////////////
49 49
 
50
-function get_host_port_from_server($server){
50
+function get_host_port_from_server($server) {
51 51
 	$values = explode(':', $server);
52
-	if (($values[0] == 'unix') && (!is_numeric( $values[1]))) {
52
+	if (($values[0] == 'unix') && (!is_numeric($values[1]))) {
53 53
 		return array($server, 0);
54 54
 	}
55 55
 	else {
@@ -57,60 +57,60 @@  discard block
 block discarded – undo
57 57
 	}
58 58
 }
59 59
 
60
-function sendMemcacheCommands($command){
60
+function sendMemcacheCommands($command) {
61 61
     global $MEMCACHE_SERVERS;
62 62
 	$result = array();
63 63
 
64
-	foreach($MEMCACHE_SERVERS as $server){
64
+	foreach ($MEMCACHE_SERVERS as $server) {
65 65
 		$strs = get_host_port_from_server($server);
66 66
 		$host = $strs[0];
67 67
 		$port = $strs[1];
68
-		$result[$server] = sendMemcacheCommand($host,$port,$command);
68
+		$result[$server] = sendMemcacheCommand($host, $port, $command);
69 69
 	}
70 70
 	return $result;
71 71
 }
72
-function sendMemcacheCommand($server,$port,$command){
72
+function sendMemcacheCommand($server, $port, $command) {
73 73
 
74
-	$s = @fsockopen($server,$port);
75
-	if (!$s){
74
+	$s = @fsockopen($server, $port);
75
+	if (!$s) {
76 76
 		die("Cant connect to:".$server.':'.$port);
77 77
 	}
78 78
 
79 79
 	fwrite($s, $command."\r\n");
80 80
 
81
-	$buf='';
81
+	$buf = '';
82 82
 	while ((!feof($s))) {
83 83
 		$buf .= fgets($s, 256);
84
-		if (strpos($buf,"END\r\n")!==false){ // stat says end
84
+		if (strpos($buf, "END\r\n") !== false) { // stat says end
85 85
 		    break;
86 86
 		}
87
-		if (strpos($buf,"DELETED\r\n")!==false || strpos($buf,"NOT_FOUND\r\n")!==false){ // delete says these
87
+		if (strpos($buf, "DELETED\r\n") !== false || strpos($buf, "NOT_FOUND\r\n") !== false) { // delete says these
88 88
 		    break;
89 89
 		}
90
-		if (strpos($buf,"OK\r\n")!==false){ // flush_all says ok
90
+		if (strpos($buf, "OK\r\n") !== false) { // flush_all says ok
91 91
 		    break;
92 92
 		}
93 93
 	}
94 94
     fclose($s);
95 95
     return parseMemcacheResults($buf);
96 96
 }
97
-function parseMemcacheResults($str){
97
+function parseMemcacheResults($str) {
98 98
     
99 99
 	$res = array();
100
-	$lines = explode("\r\n",$str);
100
+	$lines = explode("\r\n", $str);
101 101
 	$cnt = count($lines);
102
-	for($i=0; $i< $cnt; $i++){
102
+	for ($i = 0; $i < $cnt; $i++) {
103 103
 	    $line = $lines[$i];
104
-		$l = explode(' ',$line,3);
105
-		if (count($l)==3){
106
-			$res[$l[0]][$l[1]]=$l[2];
107
-			if ($l[0]=='VALUE'){ // next line is the value
104
+		$l = explode(' ', $line, 3);
105
+		if (count($l) == 3) {
106
+			$res[$l[0]][$l[1]] = $l[2];
107
+			if ($l[0] == 'VALUE') { // next line is the value
108 108
 			    $res[$l[0]][$l[1]] = array();
109
-			    list ($flag,$size)=explode(' ',$l[2]);
110
-			    $res[$l[0]][$l[1]]['stat']=array('flag'=>$flag,'size'=>$size);
111
-			    $res[$l[0]][$l[1]]['value']=$lines[++$i];
109
+			    list ($flag, $size) = explode(' ', $l[2]);
110
+			    $res[$l[0]][$l[1]]['stat'] = array('flag'=>$flag, 'size'=>$size);
111
+			    $res[$l[0]][$l[1]]['value'] = $lines[++$i];
112 112
 			}
113
-		}elseif($line=='DELETED' || $line=='NOT_FOUND' || $line=='OK'){
113
+		}elseif ($line == 'DELETED' || $line == 'NOT_FOUND' || $line == 'OK') {
114 114
 		    return $line;
115 115
 		}
116 116
 	}
@@ -118,118 +118,118 @@  discard block
 block discarded – undo
118 118
 
119 119
 }
120 120
 
121
-function dumpCacheSlab($server,$slabId,$limit){
122
-    list($host,$port) = get_host_port_from_server($server);
123
-    $resp = sendMemcacheCommand($host,$port,'stats cachedump '.$slabId.' '.$limit);
121
+function dumpCacheSlab($server, $slabId, $limit) {
122
+    list($host, $port) = get_host_port_from_server($server);
123
+    $resp = sendMemcacheCommand($host, $port, 'stats cachedump '.$slabId.' '.$limit);
124 124
 
125 125
    return $resp;
126 126
 
127 127
 }
128 128
 
129
-function flushServer($server){
130
-    list($host,$port) = get_host_port_from_server($server);
131
-    $resp = sendMemcacheCommand($host,$port,'flush_all');
129
+function flushServer($server) {
130
+    list($host, $port) = get_host_port_from_server($server);
131
+    $resp = sendMemcacheCommand($host, $port, 'flush_all');
132 132
     return $resp;
133 133
 }
134
-function getCacheItems(){
134
+function getCacheItems() {
135 135
  $items = sendMemcacheCommands('stats items');
136 136
  $serverItems = array();
137 137
  $totalItems = array();
138
- foreach ($items as $server=>$itemlist){
138
+ foreach ($items as $server=>$itemlist) {
139 139
     $serverItems[$server] = array();
140
-    $totalItems[$server]=0;
141
-    if (!isset($itemlist['STAT'])){
140
+    $totalItems[$server] = 0;
141
+    if (!isset($itemlist['STAT'])) {
142 142
         continue;
143 143
     }
144 144
 
145 145
     $iteminfo = $itemlist['STAT'];
146 146
 
147
-    foreach($iteminfo as $keyinfo=>$value){
148
-        if (preg_match('/items\:(\d+?)\:(.+?)$/',$keyinfo,$matches)){
147
+    foreach ($iteminfo as $keyinfo=>$value) {
148
+        if (preg_match('/items\:(\d+?)\:(.+?)$/', $keyinfo, $matches)) {
149 149
             $serverItems[$server][$matches[1]][$matches[2]] = $value;
150
-            if ($matches[2]=='number'){
151
-                $totalItems[$server] +=$value;
150
+            if ($matches[2] == 'number') {
151
+                $totalItems[$server] += $value;
152 152
             }
153 153
         }
154 154
     }
155 155
  }
156
- return array('items'=>$serverItems,'counts'=>$totalItems);
156
+ return array('items'=>$serverItems, 'counts'=>$totalItems);
157 157
 }
158
-function getMemcacheStats($total=true){
158
+function getMemcacheStats($total = true) {
159 159
 	$resp = sendMemcacheCommands('stats');
160
-	if ($total){
160
+	if ($total) {
161 161
 		$res = array();
162
-		foreach($resp as $server=>$r){
163
-			foreach($r['STAT'] as $key=>$row){
164
-				if (!isset($res[$key])){
165
-					$res[$key]=null;
162
+		foreach ($resp as $server=>$r) {
163
+			foreach ($r['STAT'] as $key=>$row) {
164
+				if (!isset($res[$key])) {
165
+					$res[$key] = null;
166 166
 				}
167
-				switch ($key){
167
+				switch ($key) {
168 168
 					case 'pid':
169
-						$res['pid'][$server]=$row;
169
+						$res['pid'][$server] = $row;
170 170
 						break;
171 171
 					case 'uptime':
172
-						$res['uptime'][$server]=$row;
172
+						$res['uptime'][$server] = $row;
173 173
 						break;
174 174
 					case 'time':
175
-						$res['time'][$server]=$row;
175
+						$res['time'][$server] = $row;
176 176
 						break;
177 177
 					case 'version':
178
-						$res['version'][$server]=$row;
178
+						$res['version'][$server] = $row;
179 179
 						break;
180 180
 					case 'pointer_size':
181
-						$res['pointer_size'][$server]=$row;
181
+						$res['pointer_size'][$server] = $row;
182 182
 						break;
183 183
 					case 'rusage_user':
184
-						$res['rusage_user'][$server]=$row;
184
+						$res['rusage_user'][$server] = $row;
185 185
 						break;
186 186
 					case 'rusage_system':
187
-						$res['rusage_system'][$server]=$row;
187
+						$res['rusage_system'][$server] = $row;
188 188
 						break;
189 189
 					case 'curr_items':
190
-						$res['curr_items']+=$row;
190
+						$res['curr_items'] += $row;
191 191
 						break;
192 192
 					case 'total_items':
193
-						$res['total_items']+=$row;
193
+						$res['total_items'] += $row;
194 194
 						break;
195 195
 					case 'bytes':
196
-						$res['bytes']+=$row;
196
+						$res['bytes'] += $row;
197 197
 						break;
198 198
 					case 'curr_connections':
199
-						$res['curr_connections']+=$row;
199
+						$res['curr_connections'] += $row;
200 200
 						break;
201 201
 					case 'total_connections':
202
-						$res['total_connections']+=$row;
202
+						$res['total_connections'] += $row;
203 203
 						break;
204 204
 					case 'connection_structures':
205
-						$res['connection_structures']+=$row;
205
+						$res['connection_structures'] += $row;
206 206
 						break;
207 207
 					case 'cmd_get':
208
-						$res['cmd_get']+=$row;
208
+						$res['cmd_get'] += $row;
209 209
 						break;
210 210
 					case 'cmd_set':
211
-						$res['cmd_set']+=$row;
211
+						$res['cmd_set'] += $row;
212 212
 						break;
213 213
 					case 'get_hits':
214
-						$res['get_hits']+=$row;
214
+						$res['get_hits'] += $row;
215 215
 						break;
216 216
 					case 'get_misses':
217
-						$res['get_misses']+=$row;
217
+						$res['get_misses'] += $row;
218 218
 						break;
219 219
 					case 'evictions':
220
-						$res['evictions']+=$row;
220
+						$res['evictions'] += $row;
221 221
 						break;
222 222
 					case 'bytes_read':
223
-						$res['bytes_read']+=$row;
223
+						$res['bytes_read'] += $row;
224 224
 						break;
225 225
 					case 'bytes_written':
226
-						$res['bytes_written']+=$row;
226
+						$res['bytes_written'] += $row;
227 227
 						break;
228 228
 					case 'limit_maxbytes':
229
-						$res['limit_maxbytes']+=$row;
229
+						$res['limit_maxbytes'] += $row;
230 230
 						break;
231 231
 					case 'threads':
232
-						$res['rusage_system'][$server]=$row;
232
+						$res['rusage_system'][$server] = $row;
233 233
 						break;
234 234
 				}
235 235
 			}
@@ -244,28 +244,28 @@  discard block
 block discarded – undo
244 244
 //
245 245
 // don't cache this page
246 246
 //
247
-header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
247
+header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
248 248
 header("Cache-Control: post-check=0, pre-check=0", false);
249
-header("Pragma: no-cache");                                    // HTTP/1.0
249
+header("Pragma: no-cache"); // HTTP/1.0
250 250
 
251 251
 function duration($ts) {
252 252
     global $time;
253
-    $years = (int)((($time - $ts)/(7*86400))/52.177457);
254
-    $rem = (int)(($time-$ts)-($years * 52.177457 * 7 * 86400));
255
-    $weeks = (int)(($rem)/(7*86400));
256
-    $days = (int)(($rem)/86400) - $weeks*7;
257
-    $hours = (int)(($rem)/3600) - $days*24 - $weeks*7*24;
258
-    $mins = (int)(($rem)/60) - $hours*60 - $days*24*60 - $weeks*7*24*60;
253
+    $years = (int) ((($time - $ts) / (7 * 86400)) / 52.177457);
254
+    $rem = (int) (($time - $ts) - ($years * 52.177457 * 7 * 86400));
255
+    $weeks = (int) (($rem) / (7 * 86400));
256
+    $days = (int) (($rem) / 86400) - $weeks * 7;
257
+    $hours = (int) (($rem) / 3600) - $days * 24 - $weeks * 7 * 24;
258
+    $mins = (int) (($rem) / 60) - $hours * 60 - $days * 24 * 60 - $weeks * 7 * 24 * 60;
259 259
     $str = '';
260
-    if($years==1) $str .= "$years year, ";
261
-    if($years>1) $str .= "$years years, ";
262
-    if($weeks==1) $str .= "$weeks week, ";
263
-    if($weeks>1) $str .= "$weeks weeks, ";
264
-    if($days==1) $str .= "$days day,";
265
-    if($days>1) $str .= "$days days,";
266
-    if($hours == 1) $str .= " $hours hour and";
267
-    if($hours>1) $str .= " $hours hours and";
268
-    if($mins == 1) $str .= " 1 minute";
260
+    if ($years == 1) $str .= "$years year, ";
261
+    if ($years > 1) $str .= "$years years, ";
262
+    if ($weeks == 1) $str .= "$weeks week, ";
263
+    if ($weeks > 1) $str .= "$weeks weeks, ";
264
+    if ($days == 1) $str .= "$days day,";
265
+    if ($days > 1) $str .= "$days days,";
266
+    if ($hours == 1) $str .= " $hours hour and";
267
+    if ($hours > 1) $str .= " $hours hours and";
268
+    if ($mins == 1) $str .= " 1 minute";
269 269
     else $str .= " $mins minutes";
270 270
     return $str;
271 271
 }
@@ -277,23 +277,23 @@  discard block
 block discarded – undo
277 277
 }
278 278
 
279 279
 function bsize($s) {
280
-	foreach (array('','K','M','G') as $i => $k) {
280
+	foreach (array('', 'K', 'M', 'G') as $i => $k) {
281 281
 		if ($s < 1024) break;
282
-		$s/=1024;
282
+		$s /= 1024;
283 283
 	}
284
-	return sprintf("%5.1f %sBytes",$s,$k);
284
+	return sprintf("%5.1f %sBytes", $s, $k);
285 285
 }
286 286
 
287 287
 // create menu entry
288
-function menu_entry($ob,$title) {
288
+function menu_entry($ob, $title) {
289 289
 	global $PHP_SELF;
290
-	if ($ob==$_GET['op']){
290
+	if ($ob == $_GET['op']) {
291 291
 	    return "<li><a class=\"child_active\" href=\"$PHP_SELF&op=$ob\">$title</a></li>";
292 292
 	}
293 293
 	return "<li><a class=\"active\" href=\"$PHP_SELF&op=$ob\">$title</a></li>";
294 294
 }
295 295
 
296
-function getHeader(){
296
+function getHeader() {
297 297
     $header = <<<EOB
298 298
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
299 299
 <html>
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
 
491 491
     return $header;
492 492
 }
493
-function getFooter(){
493
+function getFooter() {
494 494
     global $VERSION;
495 495
     $footer = '</div><!-- Based on apc.php '.$VERSION.'--></body>
496 496
 </html>
@@ -499,10 +499,10 @@  discard block
 block discarded – undo
499 499
     return $footer;
500 500
 
501 501
 }
502
-function getMenu(){
502
+function getMenu() {
503 503
     global $PHP_SELF;
504 504
 echo "<ol class=menu>";
505
-if ($_GET['op']!=4){
505
+if ($_GET['op'] != 4) {
506 506
 echo <<<EOB
507 507
     <li><a href="$PHP_SELF&op={$_GET['op']}">Refresh Data</a></li>
508 508
 EOB;
@@ -513,8 +513,8 @@  discard block
 block discarded – undo
513 513
 EOB;
514 514
 }
515 515
 echo
516
-	menu_entry(1,'View Host Stats'),
517
-	menu_entry(2,'Variables');
516
+	menu_entry(1, 'View Host Stats'),
517
+	menu_entry(2, 'Variables');
518 518
 
519 519
 echo <<<EOB
520 520
 	</ol>
@@ -524,26 +524,26 @@  discard block
 block discarded – undo
524 524
 
525 525
 // TODO, AUTH
526 526
 
527
-$_GET['op'] = !isset($_GET['op'])? '1':$_GET['op'];
528
-$PHP_SELF= isset($_SERVER['PHP_SELF']) ? htmlentities(strip_tags($_SERVER['PHP_SELF'],'')) : '';
527
+$_GET['op'] = !isset($_GET['op']) ? '1' : $_GET['op'];
528
+$PHP_SELF = isset($_SERVER['PHP_SELF']) ? htmlentities(strip_tags($_SERVER['PHP_SELF'], '')) : '';
529 529
 
530
-$PHP_SELF=$PHP_SELF.'?';
530
+$PHP_SELF = $PHP_SELF.'?';
531 531
 $time = time();
532 532
 // sanitize _GET
533 533
 
534
-foreach($_GET as $key=>$g){
535
-    $_GET[$key]=htmlentities($g);
534
+foreach ($_GET as $key=>$g) {
535
+    $_GET[$key] = htmlentities($g);
536 536
 }
537 537
 
538 538
 
539 539
 // singleout
540 540
 // when singleout is set, it only gives details for that server.
541
-if (isset($_GET['singleout']) && $_GET['singleout']>=0 && $_GET['singleout'] <count($MEMCACHE_SERVERS)){
541
+if (isset($_GET['singleout']) && $_GET['singleout'] >= 0 && $_GET['singleout'] < count($MEMCACHE_SERVERS)) {
542 542
     $MEMCACHE_SERVERS = array($MEMCACHE_SERVERS[$_GET['singleout']]);
543 543
 }
544 544
 
545 545
 // display images
546
-if (isset($_GET['IMG'])){
546
+if (isset($_GET['IMG'])) {
547 547
     $memcacheStats = getMemcacheStats();
548 548
     $memcacheStatsSingle = getMemcacheStats(false);
549 549
 
@@ -551,110 +551,110 @@  discard block
 block discarded – undo
551 551
 		exit(0);
552 552
 	}
553 553
 
554
-	function fill_box($im, $x, $y, $w, $h, $color1, $color2,$text='',$placeindex='') {
554
+	function fill_box($im, $x, $y, $w, $h, $color1, $color2, $text = '', $placeindex = '') {
555 555
 		global $col_black;
556
-		$x1=$x+$w-1;
557
-		$y1=$y+$h-1;
556
+		$x1 = $x + $w - 1;
557
+		$y1 = $y + $h - 1;
558 558
 
559
-		imagerectangle($im, $x, $y1, $x1+1, $y+1, $col_black);
560
-		if($y1>$y) imagefilledrectangle($im, $x, $y, $x1, $y1, $color2);
559
+		imagerectangle($im, $x, $y1, $x1 + 1, $y + 1, $col_black);
560
+		if ($y1 > $y) imagefilledrectangle($im, $x, $y, $x1, $y1, $color2);
561 561
 		else imagefilledrectangle($im, $x, $y1, $x1, $y, $color2);
562 562
 		imagerectangle($im, $x, $y1, $x1, $y, $color1);
563 563
 		if ($text) {
564
-			if ($placeindex>0) {
564
+			if ($placeindex > 0) {
565 565
 
566
-				if ($placeindex<16)
566
+				if ($placeindex < 16)
567 567
 				{
568
-					$px=5;
569
-					$py=$placeindex*12+6;
570
-					imagefilledrectangle($im, $px+90, $py+3, $px+90-4, $py-3, $color2);
571
-					imageline($im,$x,$y+$h/2,$px+90,$py,$color2);
572
-					imagestring($im,2,$px,$py-6,$text,$color1);
568
+					$px = 5;
569
+					$py = $placeindex * 12 + 6;
570
+					imagefilledrectangle($im, $px + 90, $py + 3, $px + 90 - 4, $py - 3, $color2);
571
+					imageline($im, $x, $y + $h / 2, $px + 90, $py, $color2);
572
+					imagestring($im, 2, $px, $py - 6, $text, $color1);
573 573
 
574 574
 				} else {
575
-					if ($placeindex<31) {
576
-						$px=$x+40*2;
577
-						$py=($placeindex-15)*12+6;
575
+					if ($placeindex < 31) {
576
+						$px = $x + 40 * 2;
577
+						$py = ($placeindex - 15) * 12 + 6;
578 578
 					} else {
579
-						$px=$x+40*2+100*intval(($placeindex-15)/15);
580
-						$py=($placeindex%15)*12+6;
579
+						$px = $x + 40 * 2 + 100 * intval(($placeindex - 15) / 15);
580
+						$py = ($placeindex % 15) * 12 + 6;
581 581
 					}
582
-					imagefilledrectangle($im, $px, $py+3, $px-4, $py-3, $color2);
583
-					imageline($im,$x+$w,$y+$h/2,$px,$py,$color2);
584
-					imagestring($im,2,$px+2,$py-6,$text,$color1);
582
+					imagefilledrectangle($im, $px, $py + 3, $px - 4, $py - 3, $color2);
583
+					imageline($im, $x + $w, $y + $h / 2, $px, $py, $color2);
584
+					imagestring($im, 2, $px + 2, $py - 6, $text, $color1);
585 585
 				}
586 586
 			} else {
587
-				imagestring($im,4,$x+5,$y1-16,$text,$color1);
587
+				imagestring($im, 4, $x + 5, $y1 - 16, $text, $color1);
588 588
 			}
589 589
 		}
590 590
 	}
591 591
 
592 592
 
593
-    function fill_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1,$color2,$text='',$placeindex=0) {
594
-		$r=$diameter/2;
595
-		$w=deg2rad((360+$start+($end-$start)/2)%360);
593
+    function fill_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1, $color2, $text = '', $placeindex = 0) {
594
+		$r = $diameter / 2;
595
+		$w = deg2rad((360 + $start + ($end - $start) / 2) % 360);
596 596
 
597 597
 
598 598
 		if (function_exists("imagefilledarc")) {
599 599
 			// exists only if GD 2.0.1 is avaliable
600
-			imagefilledarc($im, $centerX+1, $centerY+1, $diameter, $diameter, $start, $end, $color1, IMG_ARC_PIE);
600
+			imagefilledarc($im, $centerX + 1, $centerY + 1, $diameter, $diameter, $start, $end, $color1, IMG_ARC_PIE);
601 601
 			imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color2, IMG_ARC_PIE);
602
-			imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color1, IMG_ARC_NOFILL|IMG_ARC_EDGED);
602
+			imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color1, IMG_ARC_NOFILL | IMG_ARC_EDGED);
603 603
 		} else {
604 604
 			imagearc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color2);
605 605
 			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
606
-			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start+1)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
607
-			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end-1))   * $r, $centerY + sin(deg2rad($end))   * $r, $color2);
608
-			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end))   * $r, $centerY + sin(deg2rad($end))   * $r, $color2);
609
-			imagefill($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2, $color2);
606
+			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start + 1)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
607
+			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end - 1)) * $r, $centerY + sin(deg2rad($end)) * $r, $color2);
608
+			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end)) * $r, $centerY + sin(deg2rad($end)) * $r, $color2);
609
+			imagefill($im, $centerX + $r * cos($w) / 2, $centerY + $r * sin($w) / 2, $color2);
610 610
 		}
611 611
 		if ($text) {
612
-			if ($placeindex>0) {
613
-				imageline($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$diameter, $placeindex*12,$color1);
614
-				imagestring($im,4,$diameter, $placeindex*12,$text,$color1);
612
+			if ($placeindex > 0) {
613
+				imageline($im, $centerX + $r * cos($w) / 2, $centerY + $r * sin($w) / 2, $diameter, $placeindex * 12, $color1);
614
+				imagestring($im, 4, $diameter, $placeindex * 12, $text, $color1);
615 615
 
616 616
 			} else {
617
-				imagestring($im,4,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$text,$color1);
617
+				imagestring($im, 4, $centerX + $r * cos($w) / 2, $centerY + $r * sin($w) / 2, $text, $color1);
618 618
 			}
619 619
 		}
620 620
 	}
621 621
 	$size = GRAPH_SIZE; // image size
622
-	$image = imagecreate($size+50, $size+10);
622
+	$image = imagecreate($size + 50, $size + 10);
623 623
 
624 624
 	$col_white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
625
-	$col_red   = imagecolorallocate($image, 0xD0, 0x60,  0x30);
625
+	$col_red   = imagecolorallocate($image, 0xD0, 0x60, 0x30);
626 626
 	$col_green = imagecolorallocate($image, 0x60, 0xF0, 0x60);
627
-	$col_black = imagecolorallocate($image,   0,   0,   0);
627
+	$col_black = imagecolorallocate($image, 0, 0, 0);
628 628
 
629
-	imagecolortransparent($image,$col_white);
629
+	imagecolortransparent($image, $col_white);
630 630
 
631
-    switch ($_GET['IMG']){
631
+    switch ($_GET['IMG']) {
632 632
         case 1: // pie chart
633
-            $tsize=$memcacheStats['limit_maxbytes'];
634
-    		$avail=$tsize-$memcacheStats['bytes'];
635
-    		$x=$y=$size/2;
633
+            $tsize = $memcacheStats['limit_maxbytes'];
634
+    		$avail = $tsize - $memcacheStats['bytes'];
635
+    		$x = $y = $size / 2;
636 636
     		$angle_from = 0;
637 637
     		$fuzz = 0.000001;
638 638
 
639
-            foreach($memcacheStatsSingle as $serv=>$mcs) {
640
-    			$free = $mcs['STAT']['limit_maxbytes']-$mcs['STAT']['bytes'];
639
+            foreach ($memcacheStatsSingle as $serv=>$mcs) {
640
+    			$free = $mcs['STAT']['limit_maxbytes'] - $mcs['STAT']['bytes'];
641 641
     			$used = $mcs['STAT']['bytes'];
642 642
 
643 643
 
644
-                if ($free>0){
644
+                if ($free > 0) {
645 645
     			// draw free
646
-    			    $angle_to = ($free*360)/$tsize;
647
-                    $perc =sprintf("%.2f%%", ($free *100) / $tsize) ;
646
+    			    $angle_to = ($free * 360) / $tsize;
647
+                    $perc = sprintf("%.2f%%", ($free * 100) / $tsize);
648 648
 
649
-        			fill_arc($image,$x,$y,$size,$angle_from,$angle_from + $angle_to ,$col_black,$col_green,$perc);
650
-        			$angle_from = $angle_from + $angle_to ;
649
+        			fill_arc($image, $x, $y, $size, $angle_from, $angle_from + $angle_to, $col_black, $col_green, $perc);
650
+        			$angle_from = $angle_from + $angle_to;
651 651
                 }
652
-    			if ($used>0){
652
+    			if ($used > 0) {
653 653
     			// draw used
654
-        			$angle_to = ($used*360)/$tsize;
655
-        			$perc =sprintf("%.2f%%", ($used *100) / $tsize) ;
656
-        			fill_arc($image,$x,$y,$size,$angle_from,$angle_from + $angle_to ,$col_black,$col_red, '('.$perc.')' );
657
-                    $angle_from = $angle_from+ $angle_to ;
654
+        			$angle_to = ($used * 360) / $tsize;
655
+        			$perc = sprintf("%.2f%%", ($used * 100) / $tsize);
656
+        			fill_arc($image, $x, $y, $size, $angle_from, $angle_from + $angle_to, $col_black, $col_red, '('.$perc.')');
657
+                    $angle_from = $angle_from + $angle_to;
658 658
     			}
659 659
     			}
660 660
 
@@ -662,12 +662,12 @@  discard block
 block discarded – undo
662 662
 
663 663
         case 2: // hit miss
664 664
 
665
-            $hits = ($memcacheStats['get_hits']==0) ? 1:$memcacheStats['get_hits'];
666
-            $misses = ($memcacheStats['get_misses']==0) ? 1:$memcacheStats['get_misses'];
667
-            $total = $hits + $misses ;
665
+            $hits = ($memcacheStats['get_hits'] == 0) ? 1 : $memcacheStats['get_hits'];
666
+            $misses = ($memcacheStats['get_misses'] == 0) ? 1 : $memcacheStats['get_misses'];
667
+            $total = $hits + $misses;
668 668
 
669
-	       	fill_box($image, 30,$size,50,-$hits*($size-21)/$total,$col_black,$col_green,sprintf("%.1f%%",$hits*100/$total));
670
-		    fill_box($image,130,$size,50,-max(4,($total-$hits)*($size-21)/$total),$col_black,$col_red,sprintf("%.1f%%",$misses*100/$total));
669
+	       	fill_box($image, 30, $size, 50, -$hits * ($size - 21) / $total, $col_black, $col_green, sprintf("%.1f%%", $hits * 100 / $total));
670
+		    fill_box($image, 130, $size, 50, -max(4, ($total - $hits) * ($size - 21) / $total), $col_black, $col_red, sprintf("%.1f%%", $misses * 100 / $total));
671 671
 		break;
672 672
 		
673 673
     }
@@ -688,36 +688,36 @@  discard block
 block discarded – undo
688 688
 
689 689
         $mem_size = $memcacheStats['limit_maxbytes'];
690 690
     	$mem_used = $memcacheStats['bytes'];
691
-	    $mem_avail= $mem_size-$mem_used;
692
-	    $startTime = time()-array_sum($memcacheStats['uptime']);
691
+	    $mem_avail = $mem_size - $mem_used;
692
+	    $startTime = time() - array_sum($memcacheStats['uptime']);
693 693
 
694 694
         $curr_items = $memcacheStats['curr_items'];
695 695
         $total_items = $memcacheStats['total_items'];
696
-        $hits = ($memcacheStats['get_hits']==0) ? 1:$memcacheStats['get_hits'];
697
-        $misses = ($memcacheStats['get_misses']==0) ? 1:$memcacheStats['get_misses'];
696
+        $hits = ($memcacheStats['get_hits'] == 0) ? 1 : $memcacheStats['get_hits'];
697
+        $misses = ($memcacheStats['get_misses'] == 0) ? 1 : $memcacheStats['get_misses'];
698 698
         $sets = $memcacheStats['cmd_set'];
699 699
 
700
-       	$req_rate = sprintf("%.2f",($hits+$misses)/($time-$startTime));
701
-	    $hit_rate = sprintf("%.2f",($hits)/($time-$startTime));
702
-	    $miss_rate = sprintf("%.2f",($misses)/($time-$startTime));
703
-	    $set_rate = sprintf("%.2f",($sets)/($time-$startTime));
700
+       	$req_rate = sprintf("%.2f", ($hits + $misses) / ($time - $startTime));
701
+	    $hit_rate = sprintf("%.2f", ($hits) / ($time - $startTime));
702
+	    $miss_rate = sprintf("%.2f", ($misses) / ($time - $startTime));
703
+	    $set_rate = sprintf("%.2f", ($sets) / ($time - $startTime));
704 704
 
705 705
 	    echo <<< EOB
706 706
 		<div class="info div1"><h2>General Cache Information</h2>
707 707
 		<table cellspacing=0><tbody>
708 708
 		<tr class=tr-1><td class=td-0>PHP Version</td><td>$phpversion</td></tr>
709 709
 EOB;
710
-		echo "<tr class=tr-0><td class=td-0>Memcached Host". ((count($MEMCACHE_SERVERS)>1) ? 's':'')."</td><td>";
711
-		$i=0;
712
-		if (!isset($_GET['singleout']) && count($MEMCACHE_SERVERS)>1){
713
-    		foreach($MEMCACHE_SERVERS as $server){
714
-    		      echo ($i+1).'. <a href="'.$PHP_SELF.'&singleout='.$i++.'">'.$server.'</a><br/>';
710
+		echo "<tr class=tr-0><td class=td-0>Memcached Host".((count($MEMCACHE_SERVERS) > 1) ? 's' : '')."</td><td>";
711
+		$i = 0;
712
+		if (!isset($_GET['singleout']) && count($MEMCACHE_SERVERS) > 1) {
713
+    		foreach ($MEMCACHE_SERVERS as $server) {
714
+    		      echo ($i + 1).'. <a href="'.$PHP_SELF.'&singleout='.$i++.'">'.$server.'</a><br/>';
715 715
     		}
716 716
 		}
717
-		else{
717
+		else {
718 718
 		    echo '1.'.$MEMCACHE_SERVERS[0];
719 719
 		}
720
-		if (isset($_GET['singleout'])){
720
+		if (isset($_GET['singleout'])) {
721 721
 		      echo '<a href="'.$PHP_SELF.'">(all servers)</a><br/>';
722 722
 		}
723 723
 		echo "</td></tr>\n";
@@ -729,14 +729,14 @@  discard block
 block discarded – undo
729 729
 
730 730
 		<div class="info div1"><h2>Memcache Server Information</h2>
731 731
 EOB;
732
-        foreach($MEMCACHE_SERVERS as $server){
732
+        foreach ($MEMCACHE_SERVERS as $server) {
733 733
             echo '<table cellspacing=0><tbody>';
734
-            echo '<tr class=tr-1><td class=td-1>'.$server.'</td><td><a href="'.$PHP_SELF.'&server='.array_search($server,$MEMCACHE_SERVERS).'&op=6">[<b>Flush this server</b>]</a></td></tr>';
735
-    		echo '<tr class=tr-0><td class=td-0>Start Time</td><td>',date(DATE_FORMAT,$memcacheStatsSingle[$server]['STAT']['time']-$memcacheStatsSingle[$server]['STAT']['uptime']),'</td></tr>';
736
-    		echo '<tr class=tr-1><td class=td-0>Uptime</td><td>',duration($memcacheStatsSingle[$server]['STAT']['time']-$memcacheStatsSingle[$server]['STAT']['uptime']),'</td></tr>';
734
+            echo '<tr class=tr-1><td class=td-1>'.$server.'</td><td><a href="'.$PHP_SELF.'&server='.array_search($server, $MEMCACHE_SERVERS).'&op=6">[<b>Flush this server</b>]</a></td></tr>';
735
+    		echo '<tr class=tr-0><td class=td-0>Start Time</td><td>', date(DATE_FORMAT, $memcacheStatsSingle[$server]['STAT']['time'] - $memcacheStatsSingle[$server]['STAT']['uptime']), '</td></tr>';
736
+    		echo '<tr class=tr-1><td class=td-0>Uptime</td><td>', duration($memcacheStatsSingle[$server]['STAT']['time'] - $memcacheStatsSingle[$server]['STAT']['uptime']), '</td></tr>';
737 737
     		echo '<tr class=tr-0><td class=td-0>Memcached Server Version</td><td>'.$memcacheStatsSingle[$server]['STAT']['version'].'</td></tr>';
738
-    		echo '<tr class=tr-1><td class=td-0>Used Cache Size</td><td>',bsize($memcacheStatsSingle[$server]['STAT']['bytes']),'</td></tr>';
739
-    		echo '<tr class=tr-0><td class=td-0>Total Cache Size</td><td>',bsize($memcacheStatsSingle[$server]['STAT']['limit_maxbytes']),'</td></tr>';
738
+    		echo '<tr class=tr-1><td class=td-0>Used Cache Size</td><td>', bsize($memcacheStatsSingle[$server]['STAT']['bytes']), '</td></tr>';
739
+    		echo '<tr class=tr-0><td class=td-0>Total Cache Size</td><td>', bsize($memcacheStatsSingle[$server]['STAT']['limit_maxbytes']), '</td></tr>';
740 740
     		echo '</tbody></table>';
741 741
 	   }
742 742
     echo <<<EOB
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
 		<table cellspacing=0><tbody>
747 747
 EOB;
748 748
 
749
-	$size='width='.(GRAPH_SIZE+50).' height='.(GRAPH_SIZE+10);
749
+	$size = 'width='.(GRAPH_SIZE + 50).' height='.(GRAPH_SIZE + 10);
750 750
 	echo <<<EOB
751 751
 		<tr>
752 752
 		<td class=td-0>Cache Usage</td>
@@ -757,16 +757,16 @@  discard block
 block discarded – undo
757 757
 	echo
758 758
 		graphics_avail() ?
759 759
 			  '<tr>'.
760
-			  "<td class=td-0><img alt=\"\" $size src=\"$PHP_SELF&IMG=1&".(isset($_GET['singleout'])? 'singleout='.$_GET['singleout'].'&':'')."$time\"></td>".
761
-			  "<td class=td-1><img alt=\"\" $size src=\"$PHP_SELF&IMG=2&".(isset($_GET['singleout'])? 'singleout='.$_GET['singleout'].'&':'')."$time\"></td></tr>\n"
760
+			  "<td class=td-0><img alt=\"\" $size src=\"$PHP_SELF&IMG=1&".(isset($_GET['singleout']) ? 'singleout='.$_GET['singleout'].'&' : '')."$time\"></td>".
761
+			  "<td class=td-1><img alt=\"\" $size src=\"$PHP_SELF&IMG=2&".(isset($_GET['singleout']) ? 'singleout='.$_GET['singleout'].'&' : '')."$time\"></td></tr>\n"
762 762
 			: "",
763 763
 		'<tr>',
764
-		'<td class=td-0><span class="green box">&nbsp;</span>Free: ',bsize($mem_avail).sprintf(" (%.1f%%)",$mem_avail*100/$mem_size),"</td>\n",
765
-		'<td class=td-1><span class="green box">&nbsp;</span>Hits: ',$hits.sprintf(" (%.1f%%)",$hits*100/($hits+$misses)),"</td>\n",
764
+		'<td class=td-0><span class="green box">&nbsp;</span>Free: ', bsize($mem_avail).sprintf(" (%.1f%%)", $mem_avail * 100 / $mem_size), "</td>\n",
765
+		'<td class=td-1><span class="green box">&nbsp;</span>Hits: ', $hits.sprintf(" (%.1f%%)", $hits * 100 / ($hits + $misses)), "</td>\n",
766 766
 		'</tr>',
767 767
 		'<tr>',
768
-		'<td class=td-0><span class="red box">&nbsp;</span>Used: ',bsize($mem_used ).sprintf(" (%.1f%%)",$mem_used *100/$mem_size),"</td>\n",
769
-		'<td class=td-1><span class="red box">&nbsp;</span>Misses: ',$misses.sprintf(" (%.1f%%)",$misses*100/($hits+$misses)),"</td>\n";
768
+		'<td class=td-0><span class="red box">&nbsp;</span>Used: ', bsize($mem_used).sprintf(" (%.1f%%)", $mem_used * 100 / $mem_size), "</td>\n",
769
+		'<td class=td-1><span class="red box">&nbsp;</span>Misses: ', $misses.sprintf(" (%.1f%%)", $misses * 100 / ($hits + $misses)), "</td>\n";
770 770
 		echo <<< EOB
771 771
 	</tr>
772 772
 	</tbody></table>
@@ -789,12 +789,12 @@  discard block
 block discarded – undo
789 789
 
790 790
     case 2: // variables
791 791
 
792
-		$m=0;
793
-		$cacheItems= getCacheItems();
792
+		$m = 0;
793
+		$cacheItems = getCacheItems();
794 794
 		$items = $cacheItems['items'];
795 795
 		$totals = $cacheItems['counts'];
796 796
 		$maxDump = MAX_ITEM_DUMP;
797
-		foreach($items as $server => $entries) {
797
+		foreach ($items as $server => $entries) {
798 798
 
799 799
     	echo <<< EOB
800 800
 
@@ -803,33 +803,33 @@  discard block
 block discarded – undo
803 803
 			<tr><th>Slab Id</th><th>Info</th></tr>
804 804
 EOB;
805 805
 
806
-			foreach($entries as $slabId => $slab) {
807
-			    $dumpUrl = $PHP_SELF.'&op=2&server='.(array_search($server,$MEMCACHE_SERVERS)).'&dumpslab='.$slabId;
806
+			foreach ($entries as $slabId => $slab) {
807
+			    $dumpUrl = $PHP_SELF.'&op=2&server='.(array_search($server, $MEMCACHE_SERVERS)).'&dumpslab='.$slabId;
808 808
 				echo
809 809
 					"<tr class=tr-$m>",
810
-					"<td class=td-0><center>",'<a href="',$dumpUrl,'">',$slabId,'</a>',"</center></td>",
811
-					"<td class=td-last><b>Item count:</b> ",$slab['number'],'<br/><b>Age:</b>',duration($time-$slab['age']),'<br/> <b>Evicted:</b>',((isset($slab['evicted']) && $slab['evicted']==1)? 'Yes':'No');
812
-					if ((isset($_GET['dumpslab']) && $_GET['dumpslab']==$slabId) &&  (isset($_GET['server']) && $_GET['server']==array_search($server,$MEMCACHE_SERVERS))){
810
+					"<td class=td-0><center>", '<a href="', $dumpUrl, '">', $slabId, '</a>', "</center></td>",
811
+					"<td class=td-last><b>Item count:</b> ", $slab['number'], '<br/><b>Age:</b>', duration($time - $slab['age']), '<br/> <b>Evicted:</b>', ((isset($slab['evicted']) && $slab['evicted'] == 1) ? 'Yes' : 'No');
812
+					if ((isset($_GET['dumpslab']) && $_GET['dumpslab'] == $slabId) && (isset($_GET['server']) && $_GET['server'] == array_search($server, $MEMCACHE_SERVERS))) {
813 813
 					    echo "<br/><b>Items: item</b><br/>";
814
-					    $items = dumpCacheSlab($server,$slabId,$slab['number']);
814
+					    $items = dumpCacheSlab($server, $slabId, $slab['number']);
815 815
                         // maybe someone likes to do a pagination here :)
816
-					    $i=1;
817
-                        foreach($items['ITEM'] as $itemKey=>$itemInfo){
818
-                            $itemInfo = trim($itemInfo,'[ ]');
816
+					    $i = 1;
817
+                        foreach ($items['ITEM'] as $itemKey=>$itemInfo) {
818
+                            $itemInfo = trim($itemInfo, '[ ]');
819 819
 
820 820
 
821
-                            echo '<a href="',$PHP_SELF,'&op=4&server=',(array_search($server,$MEMCACHE_SERVERS)),'&key=',base64_encode($itemKey).'">',$itemKey,'</a>';
821
+                            echo '<a href="', $PHP_SELF, '&op=4&server=', (array_search($server, $MEMCACHE_SERVERS)), '&key=', base64_encode($itemKey).'">', $itemKey, '</a>';
822 822
                             if ($i++ % 10 == 0) {
823 823
                                 echo '<br/>';
824 824
                             }
825
-                            elseif ($i!=$slab['number']+1){
825
+                            elseif ($i != $slab['number'] + 1) {
826 826
                                 echo ',';
827 827
                             }
828 828
                         }
829 829
 					}
830 830
 
831 831
 					echo "</td></tr>";
832
-				$m=1-$m;
832
+				$m = 1 - $m;
833 833
 			}
834 834
 		echo <<<EOB
835 835
 			</tbody></table>
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
     break;
842 842
 
843 843
     case 4: //item dump
844
-        if (!isset($_GET['key']) || !isset($_GET['server'])){
844
+        if (!isset($_GET['key']) || !isset($_GET['server'])) {
845 845
             echo "No key set!";
846 846
             break;
847 847
         }
@@ -850,25 +850,25 @@  discard block
 block discarded – undo
850 850
         // somebody has to do a fix to this.
851 851
         $theKey = htmlentities(base64_decode($_GET['key']));
852 852
 
853
-        $theserver = $MEMCACHE_SERVERS[(int)$_GET['server']];
854
-        list($h,$p) = get_host_port_from_server($theserver);
855
-        $r = sendMemcacheCommand($h,$p,'get '.$theKey);
853
+        $theserver = $MEMCACHE_SERVERS[(int) $_GET['server']];
854
+        list($h, $p) = get_host_port_from_server($theserver);
855
+        $r = sendMemcacheCommand($h, $p, 'get '.$theKey);
856 856
         echo <<<EOB
857 857
         <div class="info"><table cellspacing=0><tbody>
858 858
 			<tr><th>Server<th>Key</th><th>Value</th><th>Delete</th></tr>
859 859
 EOB;
860 860
         if (!isset($r['VALUE'])) {
861
-            echo "<tr><td class=td-0>",$theserver,"</td><td class=td-0>",$theKey,
861
+            echo "<tr><td class=td-0>", $theserver, "</td><td class=td-0>", $theKey,
862 862
                  "</td><td>[The requested item was not found or has expired]</td>",
863
-                 "<td></td>","</tr>";
863
+                 "<td></td>", "</tr>";
864 864
         }
865 865
         else {
866 866
 
867
-            echo "<tr><td class=td-0>",$theserver,"</td><td class=td-0>",$theKey,
868
-                 " <br/>flag:",$r['VALUE'][$theKey]['stat']['flag'],
869
-                 " <br/>Size:",bsize($r['VALUE'][$theKey]['stat']['size']),
870
-                 "</td><td>",chunk_split($r['VALUE'][$theKey]['value'],40),"</td>",
871
-                 '<td><a href="',$PHP_SELF,'&op=5&server=',(int)$_GET['server'],'&key=',base64_encode($theKey),"\">Delete</a></td>","</tr>";
867
+            echo "<tr><td class=td-0>", $theserver, "</td><td class=td-0>", $theKey,
868
+                 " <br/>flag:", $r['VALUE'][$theKey]['stat']['flag'],
869
+                 " <br/>Size:", bsize($r['VALUE'][$theKey]['stat']['size']),
870
+                 "</td><td>", chunk_split($r['VALUE'][$theKey]['value'], 40), "</td>",
871
+                 '<td><a href="', $PHP_SELF, '&op=5&server=', (int) $_GET['server'], '&key=', base64_encode($theKey), "\">Delete</a></td>", "</tr>";
872 872
         }
873 873
         echo <<<EOB
874 874
 			</tbody></table>
@@ -876,19 +876,19 @@  discard block
 block discarded – undo
876 876
 EOB;
877 877
     break;
878 878
     case 5: // item delete
879
-    	if (!isset($_GET['key']) || !isset($_GET['server'])){
879
+    	if (!isset($_GET['key']) || !isset($_GET['server'])) {
880 880
 			echo "No key set!";
881 881
 			break;
882 882
         }
883 883
         $theKey = htmlentities(base64_decode($_GET['key']));
884
-		$theserver = $MEMCACHE_SERVERS[(int)$_GET['server']];
885
-		list($h,$p) = get_host_port_from_server($theserver);
886
-        $r = sendMemcacheCommand($h,$p,'delete '.$theKey);
884
+		$theserver = $MEMCACHE_SERVERS[(int) $_GET['server']];
885
+		list($h, $p) = get_host_port_from_server($theserver);
886
+        $r = sendMemcacheCommand($h, $p, 'delete '.$theKey);
887 887
         echo 'Deleting '.$theKey.':'.$r;
888 888
 	break;
889 889
     
890 890
    case 6: // flush server
891
-        $theserver = $MEMCACHE_SERVERS[(int)$_GET['server']];
891
+        $theserver = $MEMCACHE_SERVERS[(int) $_GET['server']];
892 892
         $r = flushServer($theserver);
893 893
         echo 'Flush  '.$theserver.":".$r;
894 894
    break;
Please login to merge, or discard this patch.