apc.php ➔ duration()   F
last analyzed

Complexity

Conditions 10
Paths 512

Size

Total Lines 41
Code Lines 30

Duplication

Lines 41
Ratio 100 %

Importance

Changes 0
Metric Value
cc 10
eloc 30
nc 512
nop 1
dl 41
loc 41
rs 3.2187
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 62 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
require_once('FindSSEnvironment.php');
3
/*
4
  +----------------------------------------------------------------------+
5
  | APC                                                                  |
6
  +----------------------------------------------------------------------+
7
  | Copyright (c) 2006-2011 The PHP Group                                |
8
  +----------------------------------------------------------------------+
9
  | This source file is subject to version 3.01 of the PHP license,      |
10
  | that is bundled with this package in the file LICENSE, and is        |
11
  | available through the world-wide-web at the following url:           |
12
  | http://www.php.net/license/3_01.txt                                  |
13
  | If you did not receive a copy of the PHP license and are unable to   |
14
  | obtain it through the world-wide-web, please send a note to          |
15
  | [email protected] so we can mail you a copy immediately.               |
16
  +----------------------------------------------------------------------+
17
  | Authors: Ralf Becker <[email protected]>                               |
18
  |          Rasmus Lerdorf <[email protected]>                             |
19
  |          Ilia Alshanetsky <[email protected]>                         |
20
  +----------------------------------------------------------------------+
21
22
   All other licensing and usage conditions are those of the PHP Group.
23
24
 */
25
26
27
$VERSION='$Id: apc.php 325483 2012-05-01 00:34:04Z rasmus $';
28
29
////////// READ OPTIONAL CONFIGURATION FILE ////////////
30
if (file_exists("apc.conf.php")) {
31
    include("apc.conf.php");
32
}
33
////////////////////////////////////////////////////////
34
35
////////// BEGIN OF DEFAULT CONFIG AREA ///////////////////////////////////////////////////////////
36
37
defaults('USE_AUTHENTICATION', 1);            // Use (internal) authentication - best choice if
38
                                            // no other authentication is available
39
                                            // If set to 0:
40
                                            //  There will be no further authentication. You
41
                                            //  will have to handle this by yourself!
42
                                            // If set to 1:
43
                                            //  You need to change ADMIN_PASSWORD to make
44
                                            //  this work!
45
defaults('ADMIN_USERNAME', SS_DEFAULT_ADMIN_USERNAME);            // Admin Username
46
defaults('ADMIN_PASSWORD', SS_DEFAULT_ADMIN_PASSWORD);    // Admin Password - CHANGE THIS TO ENABLE!!!
47
48
// (beckerr) I'm using a clear text password here, because I've no good idea how to let
49
//           users generate a md5 or crypt password in a easy way to fill it in above
50
51
//defaults('DATE_FORMAT', "d.m.Y H:i:s");	// German
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
52
defaults('DATE_FORMAT', 'Y/m/d H:i:s');    // US
53
54
defaults('GRAPH_SIZE', 200);                    // Image size
55
56
//defaults('PROXY', 'tcp://127.0.0.1:8080');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
57
58
////////// END OF DEFAULT CONFIG AREA /////////////////////////////////////////////////////////////
59
60
61
// "define if not defined"
62
function defaults($d, $v)
63
{
64
    if (!defined($d)) {
65
        define($d, $v);
66
    } // or just @define(...)
67
}
68
69
// rewrite $PHP_SELF to block XSS attacks
70
//
71
$PHP_SELF= isset($_SERVER['PHP_SELF']) ? htmlentities(strip_tags($_SERVER['PHP_SELF'], ''), ENT_QUOTES, 'UTF-8') : '';
72
$time = time();
73
$host = php_uname('n');
74
if ($host) {
75
    $host = '('.$host.')';
76
}
77
if (isset($_SERVER['SERVER_ADDR'])) {
78
    $host .= ' ('.$_SERVER['SERVER_ADDR'].')';
79
}
80
81
// operation constants
82
define('OB_HOST_STATS', 1);
83
define('OB_SYS_CACHE', 2);
84
define('OB_USER_CACHE', 3);
85
define('OB_SYS_CACHE_DIR', 4);
86
define('OB_VERSION_CHECK', 9);
87
88
// check validity of input variables
89
$vardom=array(
90
    'OB'    => '/^\d+$/',            // operational mode switch
91
    'CC'    => '/^[01]$/',            // clear cache requested
92
    'DU'    => '/^.*$/',            // Delete User Key
93
    'SH'    => '/^[a-z0-9]+$/',        // shared object description
94
95
    'IMG'    => '/^[123]$/',            // image to generate
96
    'LO'    => '/^1$/',                // login requested
97
98
    'COUNT'    => '/^\d+$/',            // number of line displayed in list
99
    'SCOPE'    => '/^[AD]$/',            // list view scope
100
    'SORT1'    => '/^[AHSMCDTZ]$/',    // first sort key
101
    'SORT2'    => '/^[DA]$/',            // second sort key
102
    'AGGR'    => '/^\d+$/',            // aggregation by dir level
103
    'SEARCH'    => '~^[a-zA-Z0-9/_.-]*$~'            // aggregation by dir level
104
);
105
106
// default cache mode
107
$cache_mode='opcode';
108
109
// cache scope
110
$scope_list=array(
111
    'A' => 'cache_list',
112
    'D' => 'deleted_list'
113
);
114
115
// handle POST and GET requests
116
if (empty($_REQUEST)) {
117
    if (!empty($_GET) && !empty($_POST)) {
118
        $_REQUEST = array_merge($_GET, $_POST);
119
    } elseif (!empty($_GET)) {
120
        $_REQUEST = $_GET;
121
    } elseif (!empty($_POST)) {
122
        $_REQUEST = $_POST;
123
    } else {
124
        $_REQUEST = array();
125
    }
126
}
127
128
// check parameter syntax
129
foreach ($vardom as $var => $dom) {
130
    if (!isset($_REQUEST[$var])) {
131
        $MYREQUEST[$var]=null;
132
    } elseif (!is_array($_REQUEST[$var]) && preg_match($dom.'D', $_REQUEST[$var])) {
133
        $MYREQUEST[$var]=$_REQUEST[$var];
134
    } else {
135
        $MYREQUEST[$var]=$_REQUEST[$var]=null;
136
    }
137
}
138
139
// check parameter sematics
140
if (empty($MYREQUEST['SCOPE'])) {
141
    $MYREQUEST['SCOPE']="A";
142
}
143
if (empty($MYREQUEST['SORT1'])) {
144
    $MYREQUEST['SORT1']="H";
145
}
146
if (empty($MYREQUEST['SORT2'])) {
147
    $MYREQUEST['SORT2']="D";
148
}
149
if (empty($MYREQUEST['OB'])) {
150
    $MYREQUEST['OB']=OB_HOST_STATS;
151
}
152
if (!isset($MYREQUEST['COUNT'])) {
153
    $MYREQUEST['COUNT']=20;
154
}
155
if (!isset($scope_list[$MYREQUEST['SCOPE']])) {
156
    $MYREQUEST['SCOPE']='A';
157
}
158
159
$MY_SELF=
160
    "$PHP_SELF".
161
    "?SCOPE=".$MYREQUEST['SCOPE'].
162
    "&SORT1=".$MYREQUEST['SORT1'].
163
    "&SORT2=".$MYREQUEST['SORT2'].
164
    "&COUNT=".$MYREQUEST['COUNT'];
165
$MY_SELF_WO_SORT=
166
    "$PHP_SELF".
167
    "?SCOPE=".$MYREQUEST['SCOPE'].
168
    "&COUNT=".$MYREQUEST['COUNT'];
169
170
// authentication needed?
171
//
172
if (!USE_AUTHENTICATION) {
173
    $AUTHENTICATED=1;
174
} else {
175
    $AUTHENTICATED=0;
176
    if (ADMIN_PASSWORD!='password' && ($MYREQUEST['LO'] == 1 || isset($_SERVER['PHP_AUTH_USER']))) {
177
        if (!isset($_SERVER['PHP_AUTH_USER']) ||
178
            !isset($_SERVER['PHP_AUTH_PW']) ||
179
            $_SERVER['PHP_AUTH_USER'] != ADMIN_USERNAME ||
180
            $_SERVER['PHP_AUTH_PW'] != ADMIN_PASSWORD) {
181
            Header("WWW-Authenticate: Basic realm=\"APC Login\"");
182
            Header("HTTP/1.0 401 Unauthorized");
183
184
            echo <<<EOB
185
                <html><body>
186
                <h1>Rejected!</h1>
187
                <big>Wrong Username or Password!</big><br/>&nbsp;<br/>&nbsp;
188
                <big><a href='$PHP_SELF?OB={$MYREQUEST['OB']}'>Continue...</a></big>
189
                </body></html>
190
EOB;
191
            exit;
192
        } else {
193
            $AUTHENTICATED=1;
194
        }
195
    }
196
}
197
198
// select cache mode
199
if ($AUTHENTICATED && $MYREQUEST['OB'] == OB_USER_CACHE) {
200
    $cache_mode='user';
201
}
202
// clear cache
203
if ($AUTHENTICATED && isset($MYREQUEST['CC']) && $MYREQUEST['CC']) {
204
    apc_clear_cache($cache_mode);
205
}
206
207
if ($AUTHENTICATED && !empty($MYREQUEST['DU'])) {
208
    apc_delete($MYREQUEST['DU']);
209
}
210
211
if (!function_exists('apc_cache_info') || !($cache=@apc_cache_info($cache_mode))) {
212
    echo "No cache info available.  APC does not appear to be running.";
213
    exit;
214
}
215
216
$cache_user = apc_cache_info('user', 1);
217
$mem=apc_sma_info();
218
219
if (!isset($cache['num_misses'])) {
220
    $cache['num_misses'] = 0;
221
}
222
if (!isset($cache['start_time'])) {
223
    $cache['start_time'] = 0;
224
}
225
if (!isset($cache['num_inserts'])) {
226
    $cache['num_inserts'] = 0;
227
}
228
if (!isset($cache['num_misses'])) {
229
    $cache['num_misses'] = 0;
230
}
231
if (!isset($cache['num_entries'])) {
232
    $cache['num_entries'] = 0;
233
}
234
if (!isset($cache['num_hits'])) {
235
    $cache['num_hits'] = 0;
236
}
237
if (!isset($cache['locking_type'])) {
238
    $cache['locking_type'] = 0;
239
}
240
if (!isset($cache['expunges'])) {
241
    $cache['expunges'] = 0;
242
}
243
244
if (!isset($cache_user['num_misses'])) {
245
    $cache_user['num_misses'] = 0;
246
}
247
if (!isset($cache_user['start_time'])) {
248
    $cache_user['start_time'] = 0;
249
}
250
if (!isset($cache_user['num_inserts'])) {
251
    $cache_user['num_inserts'] = 0;
252
}
253
if (!isset($cache_user['num_misses'])) {
254
    $cache_user['num_misses'] = 0;
255
}
256
if (!isset($cache_user['num_entries'])) {
257
    $cache_user['num_entries'] = 0;
258
}
259
if (!isset($cache_user['num_hits'])) {
260
    $cache_user['num_hits'] = 0;
261
}
262
if (!isset($cache_user['locking_type'])) {
263
    $cache_user['locking_type'] = 0;
264
}
265
if (!isset($cache_user['expunges'])) {
266
    $cache_user['expunges'] = 0;
267
}
268
269
if (empty($cache['num_hits'])) {
270
    $cache['num_hits']=1;
271
    $time++;
272
}  // Avoid division by 0 errors on a cache clear
273
274
// don't cache this page
275
//
276
header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
277
header("Cache-Control: post-check=0, pre-check=0", false);
278
header("Pragma: no-cache");                                    // HTTP/1.0
279
280 View Code Duplication
function duration($ts)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
281
{
282
    global $time;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
283
    $years = (int)((($time - $ts)/(7*86400))/52.177457);
284
    $rem = (int)(($time-$ts)-($years * 52.177457 * 7 * 86400));
285
    $weeks = (int)(($rem)/(7*86400));
286
    $days = (int)(($rem)/86400) - $weeks*7;
287
    $hours = (int)(($rem)/3600) - $days*24 - $weeks*7*24;
288
    $mins = (int)(($rem)/60) - $hours*60 - $days*24*60 - $weeks*7*24*60;
289
    $str = '';
290
    if ($years==1) {
291
        $str .= "$years year, ";
292
    }
293
    if ($years>1) {
294
        $str .= "$years years, ";
295
    }
296
    if ($weeks==1) {
297
        $str .= "$weeks week, ";
298
    }
299
    if ($weeks>1) {
300
        $str .= "$weeks weeks, ";
301
    }
302
    if ($days==1) {
303
        $str .= "$days day,";
304
    }
305
    if ($days>1) {
306
        $str .= "$days days,";
307
    }
308
    if ($hours == 1) {
309
        $str .= " $hours hour and";
310
    }
311
    if ($hours>1) {
312
        $str .= " $hours hours and";
313
    }
314
    if ($mins == 1) {
315
        $str .= " 1 minute";
316
    } else {
317
        $str .= " $mins minutes";
318
    }
319
    return $str;
320
}
321
322
// create graphics
323
//
324
function graphics_avail()
325
{
326
    return extension_loaded('gd');
327
}
328
if (isset($MYREQUEST['IMG'])) {
329
    if (!graphics_avail()) {
330
        exit(0);
331
    }
332
333 View Code Duplication
    function fill_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1, $color2, $text='', $placeindex=0)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
334
    {
335
        $r=$diameter/2;
336
        $w=deg2rad((360+$start+($end-$start)/2)%360);
337
338
339
        if (function_exists("imagefilledarc")) {
340
            // exists only if GD 2.0.1 is avaliable
341
            imagefilledarc($im, $centerX+1, $centerY+1, $diameter, $diameter, $start, $end, $color1, IMG_ARC_PIE);
342
            imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color2, IMG_ARC_PIE);
343
            imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color1, IMG_ARC_NOFILL|IMG_ARC_EDGED);
344
        } else {
345
            imagearc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color2);
346
            imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
347
            imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start+1)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
348
            imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end-1))   * $r, $centerY + sin(deg2rad($end))   * $r, $color2);
349
            imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end))   * $r, $centerY + sin(deg2rad($end))   * $r, $color2);
350
            imagefill($im, $centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2, $color2);
351
        }
352
        if ($text) {
353
            if ($placeindex>0) {
354
                imageline($im, $centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2, $diameter, $placeindex*12, $color1);
355
                imagestring($im, 4, $diameter, $placeindex*12, $text, $color1);
356
            } else {
357
                imagestring($im, 4, $centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2, $text, $color1);
358
            }
359
        }
360
    }
361
362
    function text_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1, $text, $placeindex=0)
363
    {
364
        $r=$diameter/2;
365
        $w=deg2rad((360+$start+($end-$start)/2)%360);
366
367
        if ($placeindex>0) {
368
            imageline($im, $centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2, $diameter, $placeindex*12, $color1);
369
            imagestring($im, 4, $diameter, $placeindex*12, $text, $color1);
370
        } else {
371
            imagestring($im, 4, $centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2, $text, $color1);
372
        }
373
    }
374
375 View Code Duplication
    function fill_box($im, $x, $y, $w, $h, $color1, $color2, $text='', $placeindex='')
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
376
    {
377
        global $col_black;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
378
        $x1=$x+$w-1;
379
        $y1=$y+$h-1;
380
381
        imagerectangle($im, $x, $y1, $x1+1, $y+1, $col_black);
382
        if ($y1>$y) {
383
            imagefilledrectangle($im, $x, $y, $x1, $y1, $color2);
384
        } else {
385
            imagefilledrectangle($im, $x, $y1, $x1, $y, $color2);
386
        }
387
        imagerectangle($im, $x, $y1, $x1, $y, $color1);
388
        if ($text) {
389
            if ($placeindex>0) {
390
                if ($placeindex<16) {
391
                    $px=5;
392
                    $py=$placeindex*12+6;
393
                    imagefilledrectangle($im, $px+90, $py+3, $px+90-4, $py-3, $color2);
394
                    imageline($im, $x, $y+$h/2, $px+90, $py, $color2);
395
                    imagestring($im, 2, $px, $py-6, $text, $color1);
396
                } else {
397
                    if ($placeindex<31) {
398
                        $px=$x+40*2;
399
                        $py=($placeindex-15)*12+6;
400
                    } else {
401
                        $px=$x+40*2+100*intval(($placeindex-15)/15);
402
                        $py=($placeindex%15)*12+6;
403
                    }
404
                    imagefilledrectangle($im, $px, $py+3, $px-4, $py-3, $color2);
405
                    imageline($im, $x+$w, $y+$h/2, $px, $py, $color2);
406
                    imagestring($im, 2, $px+2, $py-6, $text, $color1);
407
                }
408
            } else {
409
                imagestring($im, 4, $x+5, $y1-16, $text, $color1);
410
            }
411
        }
412
    }
413
414
415
    $size = GRAPH_SIZE; // image size
416
    if ($MYREQUEST['IMG']==3) {
417
        $image = imagecreate(2*$size+150, $size+10);
418
    } else {
419
        $image = imagecreate($size+50, $size+10);
420
    }
421
422
    $col_white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
423
    $col_red   = imagecolorallocate($image, 0xD0, 0x60, 0x30);
424
    $col_green = imagecolorallocate($image, 0x60, 0xF0, 0x60);
425
    $col_black = imagecolorallocate($image, 0, 0, 0);
426
    imagecolortransparent($image, $col_white);
427
428
    switch ($MYREQUEST['IMG']) {
429
430
    case 1:
431
        $s=$mem['num_seg']*$mem['seg_size'];
432
        $a=$mem['avail_mem'];
433
        $x=$y=$size/2;
434
        $fuzz = 0.000001;
435
436
        // This block of code creates the pie chart.  It is a lot more complex than you
437
        // would expect because we try to visualize any memory fragmentation as well.
438
        $angle_from = 0;
439
        $string_placement=array();
440
        for ($i=0; $i<$mem['num_seg']; $i++) {
441
            $ptr = 0;
442
            $free = $mem['block_lists'][$i];
443
            uasort($free, 'block_sort');
444
            foreach ($free as $block) {
445
                if ($block['offset']!=$ptr) {       // Used block
446
                    $angle_to = $angle_from+($block['offset']-$ptr)/$s;
447
                    if (($angle_to+$fuzz)>1) {
448
                        $angle_to = 1;
449
                    }
450 View Code Duplication
                    if (($angle_to*360) - ($angle_from*360) >= 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
451
                        fill_arc($image, $x, $y, $size, $angle_from*360, $angle_to*360, $col_black, $col_red);
452
                        if (($angle_to-$angle_from)>0.05) {
453
                            array_push($string_placement, array($angle_from, $angle_to));
454
                        }
455
                    }
456
                    $angle_from = $angle_to;
457
                }
458
                $angle_to = $angle_from+($block['size'])/$s;
459
                if (($angle_to+$fuzz)>1) {
460
                    $angle_to = 1;
461
                }
462 View Code Duplication
                if (($angle_to*360) - ($angle_from*360) >= 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
463
                    fill_arc($image, $x, $y, $size, $angle_from*360, $angle_to*360, $col_black, $col_green);
464
                    if (($angle_to-$angle_from)>0.05) {
465
                        array_push($string_placement, array($angle_from, $angle_to));
466
                    }
467
                }
468
                $angle_from = $angle_to;
469
                $ptr = $block['offset']+$block['size'];
470
            }
471
            if ($ptr < $mem['seg_size']) { // memory at the end
472
                $angle_to = $angle_from + ($mem['seg_size'] - $ptr)/$s;
473
                if (($angle_to+$fuzz)>1) {
474
                    $angle_to = 1;
475
                }
476
                fill_arc($image, $x, $y, $size, $angle_from*360, $angle_to*360, $col_black, $col_red);
477
                if (($angle_to-$angle_from)>0.05) {
478
                    array_push($string_placement, array($angle_from, $angle_to));
479
                }
480
            }
481
        }
482
        foreach ($string_placement as $angle) {
483
            text_arc($image, $x, $y, $size, $angle[0]*360, $angle[1]*360, $col_black, bsize($s*($angle[1]-$angle[0])));
484
        }
485
        break;
486
487 View Code Duplication
    case 2:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
488
        $s=$cache['num_hits']+$cache['num_misses'];
489
        $a=$cache['num_hits'];
490
491
        fill_box($image, 30, $size, 50, -$a*($size-21)/$s, $col_black, $col_green, sprintf("%.1f%%", $cache['num_hits']*100/$s));
492
        fill_box($image, 130, $size, 50, -max(4, ($s-$a)*($size-21)/$s), $col_black, $col_red, sprintf("%.1f%%", $cache['num_misses']*100/$s));
493
        break;
494
495
    case 3:
496
        $s=$mem['num_seg']*$mem['seg_size'];
497
        $a=$mem['avail_mem'];
498
        $x=130;
499
        $y=1;
500
        $j=1;
501
502
        // This block of code creates the bar chart.  It is a lot more complex than you
503
        // would expect because we try to visualize any memory fragmentation as well.
504
        for ($i=0; $i<$mem['num_seg']; $i++) {
505
            $ptr = 0;
506
            $free = $mem['block_lists'][$i];
507
            uasort($free, 'block_sort');
508
            foreach ($free as $block) {
509
                if ($block['offset']!=$ptr) {       // Used block
510
                    $h=(GRAPH_SIZE-5)*($block['offset']-$ptr)/$s;
511 View Code Duplication
                    if ($h>0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
512
                        $j++;
513
                        if ($j<75) {
514
                            fill_box($image, $x, $y, 50, $h, $col_black, $col_red, bsize($block['offset']-$ptr), $j);
515
                        } else {
516
                            fill_box($image, $x, $y, 50, $h, $col_black, $col_red);
517
                        }
518
                    }
519
                    $y+=$h;
520
                }
521
                $h=(GRAPH_SIZE-5)*($block['size'])/$s;
522 View Code Duplication
                if ($h>0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
523
                    $j++;
524
                    if ($j<75) {
525
                        fill_box($image, $x, $y, 50, $h, $col_black, $col_green, bsize($block['size']), $j);
526
                    } else {
527
                        fill_box($image, $x, $y, 50, $h, $col_black, $col_green);
528
                    }
529
                }
530
                $y+=$h;
531
                $ptr = $block['offset']+$block['size'];
532
            }
533
            if ($ptr < $mem['seg_size']) { // memory at the end
534
                $h = (GRAPH_SIZE-5) * ($mem['seg_size'] - $ptr) / $s;
535
                if ($h > 0) {
536
                    fill_box($image, $x, $y, 50, $h, $col_black, $col_red, bsize($mem['seg_size']-$ptr), $j++);
537
                }
538
            }
539
        }
540
        break;
541 View Code Duplication
    case 4:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
542
        $s=$cache['num_hits']+$cache['num_misses'];
543
        $a=$cache['num_hits'];
544
545
        fill_box($image, 30, $size, 50, -$a*($size-21)/$s, $col_black, $col_green, sprintf("%.1f%%", $cache['num_hits']*100/$s));
546
        fill_box($image, 130, $size, 50, -max(4, ($s-$a)*($size-21)/$s), $col_black, $col_red, sprintf("%.1f%%", $cache['num_misses']*100/$s));
547
        break;
548
549
    }
550
    header("Content-type: image/png");
551
    imagepng($image);
552
    exit;
553
}
554
555
// pretty printer for byte values
556
//
557 View Code Duplication
function bsize($s)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
558
{
559
    foreach (array('', 'K', 'M', 'G') as $i => $k) {
560
        if ($s < 1024) {
561
            break;
562
        }
563
        $s/=1024;
564
    }
565
    return sprintf("%5.1f %sBytes", $s, $k);
0 ignored issues
show
Bug introduced by
The variable $k seems to be defined by a foreach iteration on line 559. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
566
}
567
568
// sortable table header in "scripts for this host" view
569
function sortheader($key, $name, $extra='')
570
{
571
    global $MYREQUEST, $MY_SELF_WO_SORT;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
572
573
    if ($MYREQUEST['SORT1']==$key) {
574
        $MYREQUEST['SORT2'] = $MYREQUEST['SORT2']=='A' ? 'D' : 'A';
575
    }
576
    return "<a class=sortable href=\"$MY_SELF_WO_SORT$extra&SORT1=$key&SORT2=".$MYREQUEST['SORT2']."\">$name</a>";
577
}
578
579
// create menu entry
580
function menu_entry($ob, $title)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
581
{
582
    global $MYREQUEST,$MY_SELF;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
583
    if ($MYREQUEST['OB']!=$ob) {
584
        return "<li><a href=\"$MY_SELF&OB=$ob\">$title</a></li>";
585
    } elseif (empty($MYREQUEST['SH'])) {
586
        return "<li><span class=active>$title</span></li>";
587
    } else {
588
        return "<li><a class=\"child_active\" href=\"$MY_SELF&OB=$ob\">$title</a></li>";
589
    }
590
}
591
592
function put_login_link($s="Login")
0 ignored issues
show
Coding Style introduced by
put_login_link uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
593
{
594
    global $MY_SELF,$MYREQUEST,$AUTHENTICATED;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
595
    // needs ADMIN_PASSWORD to be changed!
596
    //
597
    if (!USE_AUTHENTICATION) {
598
        return;
599
    } elseif (ADMIN_PASSWORD=='password') {
600
        print <<<EOB
601
            <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>
602
EOB;
603
    } elseif ($AUTHENTICATED) {
604
        print <<<EOB
605
            '{$_SERVER['PHP_AUTH_USER']}'&nbsp;logged&nbsp;in!
606
EOB;
607
    } else {
608
        print <<<EOB
609
            <a href="$MY_SELF&LO=1&OB={$MYREQUEST['OB']}">$s</a>
610
EOB;
611
    }
612
}
613
614
function block_sort($array1, $array2)
615
{
616
    if ($array1['offset'] > $array2['offset']) {
617
        return 1;
618
    } else {
619
        return -1;
620
    }
621
}
622
623
624
?>
625
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
626
<html>
627
<head><title>APC INFO <?php echo $host ?></title>
628
<style><!--
629
body { background:white; font-size:100.01%; margin:0; padding:0; }
630
body,p,td,th,input,submit { font-size:0.8em;font-family:arial,helvetica,sans-serif; }
631
* html body   {font-size:0.8em}
632
* html p      {font-size:0.8em}
633
* html td     {font-size:0.8em}
634
* html th     {font-size:0.8em}
635
* html input  {font-size:0.8em}
636
* html submit {font-size:0.8em}
637
td { vertical-align:top }
638
a { color:black; font-weight:none; text-decoration:none; }
639
a:hover { text-decoration:underline; }
640
div.content { padding:1em 1em 1em 1em; position:absolute; width:97%; z-index:100; }
641
642
643
div.head div.login {
644
    position:absolute;
645
    right: 1em;
646
    top: 1.2em;
647
    color:white;
648
    width:6em;
649
    }
650
div.head div.login a {
651
    position:absolute;
652
    right: 0em;
653
    background:rgb(119,123,180);
654
    border:solid rgb(102,102,153) 2px;
655
    color:white;
656
    font-weight:bold;
657
    padding:0.1em 0.5em 0.1em 0.5em;
658
    text-decoration:none;
659
    }
660
div.head div.login a:hover {
661
    background:rgb(193,193,244);
662
    }
663
664
h1.apc { background:rgb(153,153,204); margin:0; padding:0.5em 1em 0.5em 1em; }
665
* html h1.apc { margin-bottom:-7px; }
666
h1.apc a:hover { text-decoration:none; color:rgb(90,90,90); }
667
h1.apc div.logo span.logo {
668
    background:rgb(119,123,180);
669
    color:black;
670
    border-right: solid black 1px;
671
    border-bottom: solid black 1px;
672
    font-style:italic;
673
    font-size:1em;
674
    padding-left:1.2em;
675
    padding-right:1.2em;
676
    text-align:right;
677
    }
678
h1.apc div.logo span.name { color:white; font-size:0.7em; padding:0 0.8em 0 2em; }
679
h1.apc div.nameinfo { color:white; display:inline; font-size:0.4em; margin-left: 3em; }
680
h1.apc div.copy { color:black; font-size:0.4em; position:absolute; right:1em; }
681
hr.apc {
682
    background:white;
683
    border-bottom:solid rgb(102,102,153) 1px;
684
    border-style:none;
685
    border-top:solid rgb(102,102,153) 10px;
686
    height:12px;
687
    margin:0;
688
    margin-top:1px;
689
    padding:0;
690
}
691
692
ol,menu { margin:1em 0 0 0; padding:0.2em; margin-left:1em;}
693
ol.menu li { display:inline; margin-right:0.7em; list-style:none; font-size:85%}
694
ol.menu a {
695
    background:rgb(153,153,204);
696
    border:solid rgb(102,102,153) 2px;
697
    color:white;
698
    font-weight:bold;
699
    margin-right:0em;
700
    padding:0.1em 0.5em 0.1em 0.5em;
701
    text-decoration:none;
702
    margin-left: 5px;
703
    }
704
ol.menu a.child_active {
705
    background:rgb(153,153,204);
706
    border:solid rgb(102,102,153) 2px;
707
    color:white;
708
    font-weight:bold;
709
    margin-right:0em;
710
    padding:0.1em 0.5em 0.1em 0.5em;
711
    text-decoration:none;
712
    border-left: solid black 5px;
713
    margin-left: 0px;
714
    }
715
ol.menu span.active {
716
    background:rgb(153,153,204);
717
    border:solid rgb(102,102,153) 2px;
718
    color:black;
719
    font-weight:bold;
720
    margin-right:0em;
721
    padding:0.1em 0.5em 0.1em 0.5em;
722
    text-decoration:none;
723
    border-left: solid black 5px;
724
    }
725
ol.menu span.inactive {
726
    background:rgb(193,193,244);
727
    border:solid rgb(182,182,233) 2px;
728
    color:white;
729
    font-weight:bold;
730
    margin-right:0em;
731
    padding:0.1em 0.5em 0.1em 0.5em;
732
    text-decoration:none;
733
    margin-left: 5px;
734
    }
735
ol.menu a:hover {
736
    background:rgb(193,193,244);
737
    text-decoration:none;
738
    }
739
740
741
div.info {
742
    background:rgb(204,204,204);
743
    border:solid rgb(204,204,204) 1px;
744
    margin-bottom:1em;
745
    }
746
div.info h2 {
747
    background:rgb(204,204,204);
748
    color:black;
749
    font-size:1em;
750
    margin:0;
751
    padding:0.1em 1em 0.1em 1em;
752
    }
753
div.info table {
754
    border:solid rgb(204,204,204) 1px;
755
    border-spacing:0;
756
    width:100%;
757
    }
758
div.info table th {
759
    background:rgb(204,204,204);
760
    color:white;
761
    margin:0;
762
    padding:0.1em 1em 0.1em 1em;
763
    }
764
div.info table th a.sortable { color:black; }
765
div.info table tr.tr-0 { background:rgb(238,238,238); }
766
div.info table tr.tr-1 { background:rgb(221,221,221); }
767
div.info table td { padding:0.3em 1em 0.3em 1em; }
768
div.info table td.td-0 { border-right:solid rgb(102,102,153) 1px; white-space:nowrap; }
769
div.info table td.td-n { border-right:solid rgb(102,102,153) 1px; }
770
div.info table td h3 {
771
    color:black;
772
    font-size:1.1em;
773
    margin-left:-0.3em;
774
    }
775
776
div.graph { margin-bottom:1em }
777
div.graph h2 { background:rgb(204,204,204);; color:black; font-size:1em; margin:0; padding:0.1em 1em 0.1em 1em; }
778
div.graph table { border:solid rgb(204,204,204) 1px; color:black; font-weight:normal; width:100%; }
779
div.graph table td.td-0 { background:rgb(238,238,238); }
780
div.graph table td.td-1 { background:rgb(221,221,221); }
781
div.graph table td { padding:0.2em 1em 0.4em 1em; }
782
783
div.div1,div.div2 { margin-bottom:1em; width:35em; }
784
div.div3 { position:absolute; left:40em; top:1em; width:580px; }
785
//div.div3 { position:absolute; left:37em; top:1em; right:1em; }
786
787
div.sorting { margin:1.5em 0em 1.5em 2em }
788
.center { text-align:center }
789
.aright { position:absolute;right:1em }
790
.right { text-align:right }
791
.ok { color:rgb(0,200,0); font-weight:bold}
792
.failed { color:rgb(200,0,0); font-weight:bold}
793
794
span.box {
795
    border: black solid 1px;
796
    border-right:solid black 2px;
797
    border-bottom:solid black 2px;
798
    padding:0 0.5em 0 0.5em;
799
    margin-right:1em;
800
}
801
span.green { background:#60F060; padding:0 0.5em 0 0.5em}
802
span.red { background:#D06030; padding:0 0.5em 0 0.5em }
803
804
div.authneeded {
805
    background:rgb(238,238,238);
806
    border:solid rgb(204,204,204) 1px;
807
    color:rgb(200,0,0);
808
    font-size:1.2em;
809
    font-weight:bold;
810
    padding:2em;
811
    text-align:center;
812
    }
813
814
input {
815
    background:rgb(153,153,204);
816
    border:solid rgb(102,102,153) 2px;
817
    color:white;
818
    font-weight:bold;
819
    margin-right:1em;
820
    padding:0.1em 0.5em 0.1em 0.5em;
821
    }
822
//-->
823
</style>
824
</head>
825
<body>
826
<div class="head">
827
    <h1 class="apc">
828
        <div class="logo"><span class="logo"><a href="http://pecl.php.net/package/APC">APC</a></span></div>
829
        <div class="nameinfo">Opcode Cache</div>
830
    </h1>
831
    <div class="login">
832
    <?php put_login_link(); ?>
833
    </div>
834
    <hr class="apc">
835
</div>
836
<?php
837
838
839
// Display main Menu
840
echo <<<EOB
841
    <ol class=menu>
842
    <li><a href="$MY_SELF&OB={$MYREQUEST['OB']}&SH={$MYREQUEST['SH']}">Refresh Data</a></li>
843
EOB;
844
echo
845
    menu_entry(1, 'View Host Stats'),
846
    menu_entry(2, 'System Cache Entries');
847
if ($AUTHENTICATED) {
848
    echo menu_entry(4, 'Per-Directory Entries');
849
}
850
echo
851
    menu_entry(3, 'User Cache Entries'),
852
    menu_entry(9, 'Version Check');
853
854
if ($AUTHENTICATED) {
855
    echo <<<EOB
856
        <li><a class="aright" href="$MY_SELF&CC=1&OB={$MYREQUEST['OB']}" onClick="javascript:return confirm('Are you sure?');">Clear $cache_mode Cache</a></li>
857
EOB;
858
}
859
echo <<<EOB
860
    </ol>
861
EOB;
862
863
864
// CONTENT
865
echo <<<EOB
866
    <div class=content>
867
EOB;
868
869
// MAIN SWITCH STATEMENT
870
871
switch ($MYREQUEST['OB']) {
872
873
874
875
876
877
// -----------------------------------------------
878
// Host Stats
879
// -----------------------------------------------
880
case OB_HOST_STATS:
881
    $mem_size = $mem['num_seg']*$mem['seg_size'];
882
    $mem_avail= $mem['avail_mem'];
883
    $mem_used = $mem_size-$mem_avail;
884
    $seg_size = bsize($mem['seg_size']);
885
    $req_rate = sprintf("%.2f", ($cache['num_hits']+$cache['num_misses'])/($time-$cache['start_time']));
886
    $hit_rate = sprintf("%.2f", ($cache['num_hits'])/($time-$cache['start_time']));
887
    $miss_rate = sprintf("%.2f", ($cache['num_misses'])/($time-$cache['start_time']));
888
    $insert_rate = sprintf("%.2f", ($cache['num_inserts'])/($time-$cache['start_time']));
889
    $req_rate_user = sprintf("%.2f", ($cache_user['num_hits']+$cache_user['num_misses'])/($time-$cache_user['start_time']));
890
    $hit_rate_user = sprintf("%.2f", ($cache_user['num_hits'])/($time-$cache_user['start_time']));
891
    $miss_rate_user = sprintf("%.2f", ($cache_user['num_misses'])/($time-$cache_user['start_time']));
892
    $insert_rate_user = sprintf("%.2f", ($cache_user['num_inserts'])/($time-$cache_user['start_time']));
893
    $apcversion = phpversion('apc');
894
    $phpversion = phpversion();
895
    $number_files = $cache['num_entries'];
896
    $size_files = bsize($cache['mem_size']);
897
    $number_vars = $cache_user['num_entries'];
898
    $size_vars = bsize($cache_user['mem_size']);
899
    $i=0;
900
    echo <<< EOB
901
        <div class="info div1"><h2>General Cache Information</h2>
902
        <table cellspacing=0><tbody>
903
        <tr class=tr-0><td class=td-0>APC Version</td><td>$apcversion</td></tr>
904
        <tr class=tr-1><td class=td-0>PHP Version</td><td>$phpversion</td></tr>
905
EOB;
906
907
    if (!empty($_SERVER['SERVER_NAME'])) {
908
        echo "<tr class=tr-0><td class=td-0>APC Host</td><td>{$_SERVER['SERVER_NAME']} $host</td></tr>\n";
909
    }
910
    if (!empty($_SERVER['SERVER_SOFTWARE'])) {
911
        echo "<tr class=tr-1><td class=td-0>Server Software</td><td>{$_SERVER['SERVER_SOFTWARE']}</td></tr>\n";
912
    }
913
914
    echo <<<EOB
915
        <tr class=tr-0><td class=td-0>Shared Memory</td><td>{$mem['num_seg']} Segment(s) with $seg_size
916
    <br/> ({$cache['memory_type']} memory, {$cache['locking_type']} locking)
917
    </td></tr>
918
EOB;
919
    echo   '<tr class=tr-1><td class=td-0>Start Time</td><td>',date(DATE_FORMAT, $cache['start_time']),'</td></tr>';
920
    echo   '<tr class=tr-0><td class=td-0>Uptime</td><td>',duration($cache['start_time']),'</td></tr>';
921
    echo   '<tr class=tr-1><td class=td-0>File Upload Support</td><td>',$cache['file_upload_progress'],'</td></tr>';
922
    echo <<<EOB
923
        </tbody></table>
924
        </div>
925
926
        <div class="info div1"><h2>File Cache Information</h2>
927
        <table cellspacing=0><tbody>
928
        <tr class=tr-0><td class=td-0>Cached Files</td><td>$number_files ($size_files)</td></tr>
929
        <tr class=tr-1><td class=td-0>Hits</td><td>{$cache['num_hits']}</td></tr>
930
        <tr class=tr-0><td class=td-0>Misses</td><td>{$cache['num_misses']}</td></tr>
931
        <tr class=tr-1><td class=td-0>Request Rate (hits, misses)</td><td>$req_rate cache requests/second</td></tr>
932
        <tr class=tr-0><td class=td-0>Hit Rate</td><td>$hit_rate cache requests/second</td></tr>
933
        <tr class=tr-1><td class=td-0>Miss Rate</td><td>$miss_rate cache requests/second</td></tr>
934
        <tr class=tr-0><td class=td-0>Insert Rate</td><td>$insert_rate cache requests/second</td></tr>
935
        <tr class=tr-1><td class=td-0>Cache full count</td><td>{$cache['expunges']}</td></tr>
936
        </tbody></table>
937
        </div>
938
939
        <div class="info div1"><h2>User Cache Information</h2>
940
        <table cellspacing=0><tbody>
941
    <tr class=tr-0><td class=td-0>Cached Variables</td><td>$number_vars ($size_vars)</td></tr>
942
        <tr class=tr-1><td class=td-0>Hits</td><td>{$cache_user['num_hits']}</td></tr>
943
        <tr class=tr-0><td class=td-0>Misses</td><td>{$cache_user['num_misses']}</td></tr>
944
        <tr class=tr-1><td class=td-0>Request Rate (hits, misses)</td><td>$req_rate_user cache requests/second</td></tr>
945
        <tr class=tr-0><td class=td-0>Hit Rate</td><td>$hit_rate_user cache requests/second</td></tr>
946
        <tr class=tr-1><td class=td-0>Miss Rate</td><td>$miss_rate_user cache requests/second</td></tr>
947
        <tr class=tr-0><td class=td-0>Insert Rate</td><td>$insert_rate_user cache requests/second</td></tr>
948
        <tr class=tr-1><td class=td-0>Cache full count</td><td>{$cache_user['expunges']}</td></tr>
949
950
        </tbody></table>
951
        </div>
952
953
        <div class="info div2"><h2>Runtime Settings</h2><table cellspacing=0><tbody>
954
EOB;
955
956
    $j = 0;
957
    foreach (ini_get_all('apc') as $k => $v) {
958
        echo "<tr class=tr-$j><td class=td-0>",$k,"</td><td>",str_replace(',', ',<br />', $v['local_value']),"</td></tr>\n";
959
        $j = 1 - $j;
960
    }
961
962
    if ($mem['num_seg']>1 || $mem['num_seg']==1 && count($mem['block_lists'][0])>1) {
963
        $mem_note = "Memory Usage<br /><font size=-2>(multiple slices indicate fragments)</font>";
964
    } else {
965
        $mem_note = "Memory Usage";
966
    }
967
968
    echo <<< EOB
969
        </tbody></table>
970
        </div>
971
972
        <div class="graph div3"><h2>Host Status Diagrams</h2>
973
        <table cellspacing=0><tbody>
974
EOB;
975
    $size='width='.(GRAPH_SIZE+50).' height='.(GRAPH_SIZE+10);
976
    echo <<<EOB
977
        <tr>
978
        <td class=td-0>$mem_note</td>
979
        <td class=td-1>Hits &amp; Misses</td>
980
        </tr>
981
EOB;
982
983
    echo
984
        graphics_avail() ?
985
              '<tr>'.
986
              "<td class=td-0><img alt=\"\" $size src=\"$PHP_SELF?IMG=1&$time\"></td>".
987
              "<td class=td-1><img alt=\"\" $size src=\"$PHP_SELF?IMG=2&$time\"></td></tr>\n"
988
            : "",
989
        '<tr>',
990
        '<td class=td-0><span class="green box">&nbsp;</span>Free: ',bsize($mem_avail).sprintf(" (%.1f%%)", $mem_avail*100/$mem_size),"</td>\n",
991
        '<td class=td-1><span class="green box">&nbsp;</span>Hits: ',$cache['num_hits'].sprintf(" (%.1f%%)", $cache['num_hits']*100/($cache['num_hits']+$cache['num_misses'])),"</td>\n",
992
        '</tr>',
993
        '<tr>',
994
        '<td class=td-0><span class="red box">&nbsp;</span>Used: ',bsize($mem_used).sprintf(" (%.1f%%)", $mem_used *100/$mem_size),"</td>\n",
995
        '<td class=td-1><span class="red box">&nbsp;</span>Misses: ',$cache['num_misses'].sprintf(" (%.1f%%)", $cache['num_misses']*100/($cache['num_hits']+$cache['num_misses'])),"</td>\n";
996
    echo <<< EOB
997
        </tr>
998
        </tbody></table>
999
1000
        <br/>
1001
        <h2>Detailed Memory Usage and Fragmentation</h2>
1002
        <table cellspacing=0><tbody>
1003
        <tr>
1004
        <td class=td-0 colspan=2><br/>
1005
EOB;
1006
1007
    // Fragementation: (freeseg - 1) / total_seg
1008
    $nseg = $freeseg = $fragsize = $freetotal = 0;
1009
    for ($i=0; $i<$mem['num_seg']; $i++) {
1010
        $ptr = 0;
1011
        foreach ($mem['block_lists'][$i] as $block) {
1012
            if ($block['offset'] != $ptr) {
1013
                ++$nseg;
1014
            }
1015
            $ptr = $block['offset'] + $block['size'];
1016
            /* Only consider blocks <5M for the fragmentation % */
1017
            if ($block['size']<(5*1024*1024)) {
1018
                $fragsize+=$block['size'];
1019
            }
1020
            $freetotal+=$block['size'];
1021
        }
1022
        $freeseg += count($mem['block_lists'][$i]);
1023
    }
1024
1025
    if ($freeseg > 1) {
1026
        $frag = sprintf("%.2f%% (%s out of %s in %d fragments)", ($fragsize/$freetotal)*100, bsize($fragsize), bsize($freetotal), $freeseg);
1027
    } else {
1028
        $frag = "0%";
1029
    }
1030
1031
    if (graphics_avail()) {
1032
        $size='width='.(2*GRAPH_SIZE+150).' height='.(GRAPH_SIZE+10);
1033
        echo <<<EOB
1034
            <img alt="" $size src="$PHP_SELF?IMG=3&$time">
1035
EOB;
1036
    }
1037
    echo <<<EOB
1038
        </br>Fragmentation: $frag
1039
        </td>
1040
        </tr>
1041
EOB;
1042
        if (isset($mem['adist'])) {
1043
            foreach ($mem['adist'] as $i=>$v) {
0 ignored issues
show
Bug introduced by
The expression $mem['adist'] of type integer|double is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
1044
                $cur = pow(2, $i);
1045
                $nxt = pow(2, $i+1)-1;
1046
                if ($i==0) {
1047
                    $range = "1";
1048
                } else {
1049
                    $range = "$cur - $nxt";
1050
                }
1051
                echo "<tr><th align=right>$range</th><td align=right>$v</td></tr>\n";
1052
            }
1053
        }
1054
        echo <<<EOB
1055
        </tbody></table>
1056
        </div>
1057
EOB;
1058
1059
    break;
1060
1061
1062
// -----------------------------------------------
1063
// User Cache Entries
1064
// -----------------------------------------------
1065
case OB_USER_CACHE:
1066
    if (!$AUTHENTICATED) {
1067
        echo '<div class="error">You need to login to see the user values here!<br/>&nbsp;<br/>';
1068
        put_login_link("Login now!");
1069
        echo '</div>';
1070
        break;
1071
    }
1072
    $fieldname='info';
1073
    $fieldheading='User Entry Label';
1074
    $fieldkey='info';
1075
1076
// -----------------------------------------------
1077
// System Cache Entries
1078
// -----------------------------------------------
1079
// no break
1080
case OB_SYS_CACHE:
1081
    if (!isset($fieldname)) {
1082
        $fieldname='filename';
1083
        $fieldheading='Script Filename';
1084
        if (ini_get("apc.stat")) {
1085
            $fieldkey='inode';
1086
        } else {
1087
            $fieldkey='filename';
1088
        }
1089
    }
1090
    if (!empty($MYREQUEST['SH'])) {
1091
        echo <<< EOB
1092
            <div class="info"><table cellspacing=0><tbody>
1093
            <tr><th>Attribute</th><th>Value</th></tr>
1094
EOB;
1095
1096
        $m=0;
1097
        foreach ($scope_list as $j => $list) {
1098
            foreach ($cache[$list] as $i => $entry) {
1099
                if (md5($entry[$fieldkey])!=$MYREQUEST['SH']) {
1100
                    continue;
1101
                }
1102
                foreach ($entry as $k => $value) {
1103
                    if (!$AUTHENTICATED) {
1104
                        // hide all path entries if not logged in
1105
                        $value=preg_replace('/^.*(\\/|\\\\)/', '<i>&lt;hidden&gt;</i>/', $value);
1106
                    }
1107
1108
                    if ($k == "num_hits") {
1109
                        $value=sprintf("%s (%.2f%%)", $value, $value*100/$cache['num_hits']);
1110
                    }
1111
                    if ($k == 'deletion_time') {
1112
                        if (!$entry['deletion_time']) {
1113
                            $value = "None";
1114
                        }
1115
                    }
1116
                    echo
1117
                        "<tr class=tr-$m>",
1118
                        "<td class=td-0>",ucwords(preg_replace("/_/", " ", $k)),"</td>",
1119
                        "<td class=td-last>",(preg_match("/time/", $k) && $value!='None') ? date(DATE_FORMAT, $value) : htmlspecialchars($value, ENT_QUOTES, 'UTF-8'),"</td>",
1120
                        "</tr>";
1121
                    $m=1-$m;
1122
                }
1123
                if ($fieldkey=='info') {
1124
                    echo "<tr class=tr-$m><td class=td-0>Stored Value</td><td class=td-last><pre>";
1125
                    $output = var_export(apc_fetch($entry[$fieldkey]), true);
1126
                    echo htmlspecialchars($output, ENT_QUOTES, 'UTF-8');
1127
                    echo "</pre></td></tr>\n";
1128
                }
1129
                break;
1130
            }
1131
        }
1132
1133
        echo <<<EOB
1134
            </tbody></table>
1135
            </div>
1136
EOB;
1137
        break;
1138
    }
1139
1140
    $cols=6;
1141
    echo <<<EOB
1142
        <div class=sorting><form>Scope:
1143
        <input type=hidden name=OB value={$MYREQUEST['OB']}>
1144
        <select name=SCOPE>
1145
EOB;
1146
    echo
1147
        "<option value=A",$MYREQUEST['SCOPE']=='A' ? " selected":"",">Active</option>",
1148
        "<option value=D",$MYREQUEST['SCOPE']=='D' ? " selected":"",">Deleted</option>",
1149
        "</select>",
1150
        ", Sorting:<select name=SORT1>",
1151
        "<option value=H",$MYREQUEST['SORT1']=='H' ? " selected":"",">Hits</option>",
1152
        "<option value=Z",$MYREQUEST['SORT1']=='Z' ? " selected":"",">Size</option>",
1153
        "<option value=S",$MYREQUEST['SORT1']=='S' ? " selected":"",">$fieldheading</option>",
1154
        "<option value=A",$MYREQUEST['SORT1']=='A' ? " selected":"",">Last accessed</option>",
1155
        "<option value=M",$MYREQUEST['SORT1']=='M' ? " selected":"",">Last modified</option>",
1156
        "<option value=C",$MYREQUEST['SORT1']=='C' ? " selected":"",">Created at</option>",
1157
        "<option value=D",$MYREQUEST['SORT1']=='D' ? " selected":"",">Deleted at</option>";
1158
    if ($fieldname=='info') {
1159
        echo
1160
        "<option value=D",$MYREQUEST['SORT1']=='T' ? " selected":"",">Timeout</option>";
1161
    }
1162
    echo
1163
        '</select>',
1164
        '<select name=SORT2>',
1165
        '<option value=D',$MYREQUEST['SORT2']=='D' ? ' selected':'','>DESC</option>',
1166
        '<option value=A',$MYREQUEST['SORT2']=='A' ? ' selected':'','>ASC</option>',
1167
        '</select>',
1168
        '<select name=COUNT onChange="form.submit()">',
1169
        '<option value=10 ',$MYREQUEST['COUNT']=='10' ? ' selected':'','>Top 10</option>',
1170
        '<option value=20 ',$MYREQUEST['COUNT']=='20' ? ' selected':'','>Top 20</option>',
1171
        '<option value=50 ',$MYREQUEST['COUNT']=='50' ? ' selected':'','>Top 50</option>',
1172
        '<option value=100',$MYREQUEST['COUNT']=='100'? ' selected':'','>Top 100</option>',
1173
        '<option value=150',$MYREQUEST['COUNT']=='150'? ' selected':'','>Top 150</option>',
1174
        '<option value=200',$MYREQUEST['COUNT']=='200'? ' selected':'','>Top 200</option>',
1175
        '<option value=500',$MYREQUEST['COUNT']=='500'? ' selected':'','>Top 500</option>',
1176
        '<option value=0  ',$MYREQUEST['COUNT']=='0'  ? ' selected':'','>All</option>',
1177
        '</select>',
1178
    '&nbsp; Search: <input name=SEARCH value="',$MYREQUEST['SEARCH'],'" type=text size=25/>',
1179
        '&nbsp;<input type=submit value="GO!">',
1180
        '</form></div>';
1181
1182
  if (isset($MYREQUEST['SEARCH'])) {
1183
      // Don't use preg_quote because we want the user to be able to specify a
1184
      // regular expression subpattern.
1185
      $MYREQUEST['SEARCH'] = '/'.str_replace('/', '\\/', $MYREQUEST['SEARCH']).'/i';
1186
      if (preg_match($MYREQUEST['SEARCH'], 'test') === false) {
1187
          echo '<div class="error">Error: enter a valid regular expression as a search query.</div>';
1188
          break;
1189
      }
1190
  }
1191
1192
  echo
1193
        '<div class="info"><table cellspacing=0><tbody>',
1194
        '<tr>',
1195
        '<th>',sortheader('S', $fieldheading, "&OB=".$MYREQUEST['OB']),'</th>',
1196
        '<th>',sortheader('H', 'Hits', "&OB=".$MYREQUEST['OB']),'</th>',
1197
        '<th>',sortheader('Z', 'Size', "&OB=".$MYREQUEST['OB']),'</th>',
1198
        '<th>',sortheader('A', 'Last accessed', "&OB=".$MYREQUEST['OB']),'</th>',
1199
        '<th>',sortheader('M', 'Last modified', "&OB=".$MYREQUEST['OB']),'</th>',
1200
        '<th>',sortheader('C', 'Created at', "&OB=".$MYREQUEST['OB']),'</th>';
1201
1202
    if ($fieldname=='info') {
1203
        $cols+=2;
1204
        echo '<th>',sortheader('T', 'Timeout', "&OB=".$MYREQUEST['OB']),'</th>';
1205
    }
1206
    echo '<th>',sortheader('D', 'Deleted at', "&OB=".$MYREQUEST['OB']),'</th></tr>';
1207
1208
    // builds list with alpha numeric sortable keys
1209
    //
1210
    $list = array();
1211
    foreach ($cache[$scope_list[$MYREQUEST['SCOPE']]] as $i => $entry) {
1212
        switch ($MYREQUEST['SORT1']) {
1213
            case 'A': $k=sprintf('%015d-', $entry['access_time']);    break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1214
            case 'H': $k=sprintf('%015d-', $entry['num_hits']);        break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1215
            case 'Z': $k=sprintf('%015d-', $entry['mem_size']);        break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1216
            case 'M': $k=sprintf('%015d-', $entry['mtime']);            break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1217
            case 'C': $k=sprintf('%015d-', $entry['creation_time']);    break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1218
            case 'T': $k=sprintf('%015d-', $entry['ttl']);            break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1219
            case 'D': $k=sprintf('%015d-', $entry['deletion_time']);    break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1220
            case 'S': $k='';                                        break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1221
        }
1222
        if (!$AUTHENTICATED) {
1223
            // hide all path entries if not logged in
1224
            $list[$k.$entry[$fieldname]]=preg_replace('/^.*(\\/|\\\\)/', '*hidden*/', $entry);
1225
        } else {
1226
            $list[$k.$entry[$fieldname]]=$entry;
1227
        }
1228
    }
1229
1230
    if ($list) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $list of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1231
1232
        // sort list
1233
        //
1234 View Code Duplication
        switch ($MYREQUEST['SORT2']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1235
            case "A":    krsort($list);    break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1236
            case "D":    ksort($list);    break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1237
        }
1238
1239
        // output list
1240
        $i=0;
1241
        foreach ($list as $k => $entry) {
1242
            if (!$MYREQUEST['SEARCH'] || preg_match($MYREQUEST['SEARCH'], $entry[$fieldname]) != 0) {
1243
                $field_value = htmlentities(strip_tags($entry[$fieldname], ''), ENT_QUOTES, 'UTF-8');
1244
                echo
1245
          '<tr class=tr-',$i%2,'>',
1246
          "<td class=td-0><a href=\"$MY_SELF&OB=",$MYREQUEST['OB'],"&SH=",md5($entry[$fieldkey]),"\">",$field_value,'</a></td>',
1247
          '<td class="td-n center">',$entry['num_hits'],'</td>',
1248
          '<td class="td-n right">',$entry['mem_size'],'</td>',
1249
          '<td class="td-n center">',date(DATE_FORMAT, $entry['access_time']),'</td>',
1250
          '<td class="td-n center">',date(DATE_FORMAT, $entry['mtime']),'</td>',
1251
          '<td class="td-n center">',date(DATE_FORMAT, $entry['creation_time']),'</td>';
1252
1253
                if ($fieldname=='info') {
1254
                    if ($entry['ttl']) {
1255
                        echo '<td class="td-n center">'.$entry['ttl'].' seconds</td>';
1256
                    } else {
1257
                        echo '<td class="td-n center">None</td>';
1258
                    }
1259
                }
1260
                if ($entry['deletion_time']) {
1261
                    echo '<td class="td-last center">', date(DATE_FORMAT, $entry['deletion_time']), '</td>';
1262
                } elseif ($MYREQUEST['OB'] == OB_USER_CACHE) {
1263
                    echo '<td class="td-last center">';
1264
                    echo '[<a href="', $MY_SELF, '&OB=', $MYREQUEST['OB'], '&DU=', urlencode($entry[$fieldkey]), '">Delete Now</a>]';
1265
                    echo '</td>';
1266
                } else {
1267
                    echo '<td class="td-last center"> &nbsp; </td>';
1268
                }
1269
                echo '</tr>';
1270
                $i++;
1271
                if ($i == $MYREQUEST['COUNT']) {
1272
                    break;
1273
                }
1274
            }
1275
        }
1276
    } else {
1277
        echo '<tr class=tr-0><td class="center" colspan=',$cols,'><i>No data</i></td></tr>';
1278
    }
1279
    echo <<< EOB
1280
        </tbody></table>
1281
EOB;
1282
1283 View Code Duplication
    if ($list && $i < count($list)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $list of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1284
        echo "<a href=\"$MY_SELF&OB=",$MYREQUEST['OB'],"&COUNT=0\"><i>",count($list)-$i,' more available...</i></a>';
1285
    }
1286
1287
    echo <<< EOB
1288
        </div>
1289
EOB;
1290
    break;
1291
1292
1293
// -----------------------------------------------
1294
// Per-Directory System Cache Entries
1295
// -----------------------------------------------
1296
case OB_SYS_CACHE_DIR:
1297
    if (!$AUTHENTICATED) {
1298
        break;
1299
    }
1300
1301
    echo <<<EOB
1302
        <div class=sorting><form>Scope:
1303
        <input type=hidden name=OB value={$MYREQUEST['OB']}>
1304
        <select name=SCOPE>
1305
EOB;
1306
    echo
1307
        "<option value=A",$MYREQUEST['SCOPE']=='A' ? " selected":"",">Active</option>",
1308
        "<option value=D",$MYREQUEST['SCOPE']=='D' ? " selected":"",">Deleted</option>",
1309
        "</select>",
1310
        ", Sorting:<select name=SORT1>",
1311
        "<option value=H",$MYREQUEST['SORT1']=='H' ? " selected":"",">Total Hits</option>",
1312
        "<option value=Z",$MYREQUEST['SORT1']=='Z' ? " selected":"",">Total Size</option>",
1313
        "<option value=T",$MYREQUEST['SORT1']=='T' ? " selected":"",">Number of Files</option>",
1314
        "<option value=S",$MYREQUEST['SORT1']=='S' ? " selected":"",">Directory Name</option>",
1315
        "<option value=A",$MYREQUEST['SORT1']=='A' ? " selected":"",">Avg. Size</option>",
1316
        "<option value=C",$MYREQUEST['SORT1']=='C' ? " selected":"",">Avg. Hits</option>",
1317
        '</select>',
1318
        '<select name=SORT2>',
1319
        '<option value=D',$MYREQUEST['SORT2']=='D' ? ' selected':'','>DESC</option>',
1320
        '<option value=A',$MYREQUEST['SORT2']=='A' ? ' selected':'','>ASC</option>',
1321
        '</select>',
1322
        '<select name=COUNT onChange="form.submit()">',
1323
        '<option value=10 ',$MYREQUEST['COUNT']=='10' ? ' selected':'','>Top 10</option>',
1324
        '<option value=20 ',$MYREQUEST['COUNT']=='20' ? ' selected':'','>Top 20</option>',
1325
        '<option value=50 ',$MYREQUEST['COUNT']=='50' ? ' selected':'','>Top 50</option>',
1326
        '<option value=100',$MYREQUEST['COUNT']=='100'? ' selected':'','>Top 100</option>',
1327
        '<option value=150',$MYREQUEST['COUNT']=='150'? ' selected':'','>Top 150</option>',
1328
        '<option value=200',$MYREQUEST['COUNT']=='200'? ' selected':'','>Top 200</option>',
1329
        '<option value=500',$MYREQUEST['COUNT']=='500'? ' selected':'','>Top 500</option>',
1330
        '<option value=0  ',$MYREQUEST['COUNT']=='0'  ? ' selected':'','>All</option>',
1331
        '</select>',
1332
        ", Group By Dir Level:<select name=AGGR>",
1333
        "<option value='' selected>None</option>";
1334
        for ($i = 1; $i < 10; $i++) {
1335
            echo "<option value=$i",$MYREQUEST['AGGR']==$i ? " selected":"",">$i</option>";
1336
        }
1337
        echo '</select>',
1338
        '&nbsp;<input type=submit value="GO!">',
1339
        '</form></div>',
1340
1341
        '<div class="info"><table cellspacing=0><tbody>',
1342
        '<tr>',
1343
        '<th>',sortheader('S', 'Directory Name', "&OB=".$MYREQUEST['OB']),'</th>',
1344
        '<th>',sortheader('T', 'Number of Files', "&OB=".$MYREQUEST['OB']),'</th>',
1345
        '<th>',sortheader('H', 'Total Hits', "&OB=".$MYREQUEST['OB']),'</th>',
1346
        '<th>',sortheader('Z', 'Total Size', "&OB=".$MYREQUEST['OB']),'</th>',
1347
        '<th>',sortheader('C', 'Avg. Hits', "&OB=".$MYREQUEST['OB']),'</th>',
1348
        '<th>',sortheader('A', 'Avg. Size', "&OB=".$MYREQUEST['OB']),'</th>',
1349
        '</tr>';
1350
1351
    // builds list with alpha numeric sortable keys
1352
    //
1353
    $tmp = $list = array();
1354
    foreach ($cache[$scope_list[$MYREQUEST['SCOPE']]] as $entry) {
1355
        $n = dirname($entry['filename']);
1356
        if ($MYREQUEST['AGGR'] > 0) {
1357
            $n = preg_replace("!^(/?(?:[^/\\\\]+[/\\\\]){".($MYREQUEST['AGGR']-1)."}[^/\\\\]*).*!", "$1", $n);
1358
        }
1359
        if (!isset($tmp[$n])) {
1360
            $tmp[$n] = array('hits'=>0,'size'=>0,'ents'=>0);
1361
        }
1362
        $tmp[$n]['hits'] += $entry['num_hits'];
1363
        $tmp[$n]['size'] += $entry['mem_size'];
1364
        ++$tmp[$n]['ents'];
1365
    }
1366
1367
    foreach ($tmp as $k => $v) {
1368
        switch ($MYREQUEST['SORT1']) {
1369
            case 'A': $kn=sprintf('%015d-', $v['size'] / $v['ents']);break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1370
            case 'T': $kn=sprintf('%015d-', $v['ents']);        break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1371
            case 'H': $kn=sprintf('%015d-', $v['hits']);        break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1372
            case 'Z': $kn=sprintf('%015d-', $v['size']);        break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1373
            case 'C': $kn=sprintf('%015d-', $v['hits'] / $v['ents']);break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1374
            case 'S': $kn = $k;                    break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1375
        }
1376
        $list[$kn.$k] = array($k, $v['ents'], $v['hits'], $v['size']);
1377
    }
1378
1379
    if ($list) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $list of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1380
1381
        // sort list
1382
        //
1383 View Code Duplication
        switch ($MYREQUEST['SORT2']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1384
            case "A":    krsort($list);    break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1385
            case "D":    ksort($list);    break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
1386
        }
1387
1388
        // output list
1389
        $i = 0;
1390
        foreach ($list as $entry) {
1391
            echo
1392
                '<tr class=tr-',$i%2,'>',
1393
                "<td class=td-0>",$entry[0],'</a></td>',
1394
                '<td class="td-n center">',$entry[1],'</td>',
1395
                '<td class="td-n center">',$entry[2],'</td>',
1396
                '<td class="td-n center">',$entry[3],'</td>',
1397
                '<td class="td-n center">',round($entry[2] / $entry[1]),'</td>',
1398
                '<td class="td-n center">',round($entry[3] / $entry[1]),'</td>',
1399
                '</tr>';
1400
1401
            if (++$i == $MYREQUEST['COUNT']) {
1402
                break;
1403
            }
1404
        }
1405
    } else {
1406
        echo '<tr class=tr-0><td class="center" colspan=6><i>No data</i></td></tr>';
1407
    }
1408
    echo <<< EOB
1409
        </tbody></table>
1410
EOB;
1411
1412 View Code Duplication
    if ($list && $i < count($list)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $list of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1413
        echo "<a href=\"$MY_SELF&OB=",$MYREQUEST['OB'],"&COUNT=0\"><i>",count($list)-$i,' more available...</i></a>';
1414
    }
1415
1416
    echo <<< EOB
1417
        </div>
1418
EOB;
1419
    break;
1420
1421
// -----------------------------------------------
1422
// Version check
1423
// -----------------------------------------------
1424
case OB_VERSION_CHECK:
1425
    echo <<<EOB
1426
        <div class="info"><h2>APC Version Information</h2>
1427
        <table cellspacing=0><tbody>
1428
        <tr>
1429
        <th></th>
1430
        </tr>
1431
EOB;
1432
  if (defined('PROXY')) {
1433
      $ctxt = stream_context_create(array( 'http' => array( 'proxy' => PROXY, 'request_fulluri' => true ) ));
1434
      $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apc.rss", false, $ctxt);
1435
  } else {
1436
      $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apc.rss");
1437
  }
1438
    if (!$rss) {
1439
        echo '<tr class="td-last center"><td>Unable to fetch version information.</td></tr>';
1440
    } else {
1441
        $apcversion = phpversion('apc');
1442
1443
        preg_match('!<title>APC ([0-9.]+)</title>!', $rss, $match);
1444
        echo '<tr class="tr-0 center"><td>';
1445
        if (version_compare($apcversion, $match[1], '>=')) {
1446
            echo '<div class="ok">You are running the latest version of APC ('.$apcversion.')</div>';
1447
            $i = 3;
1448
        } else {
1449
            echo '<div class="failed">You are running an older version of APC ('.$apcversion.'),
1450
                newer version '.$match[1].' is available at <a href="http://pecl.php.net/package/APC/'.$match[1].'">
1451
                http://pecl.php.net/package/APC/'.$match[1].'</a>
1452
                </div>';
1453
            $i = -1;
1454
        }
1455
        echo '</td></tr>';
1456
        echo '<tr class="tr-0"><td><h3>Change Log:</h3><br/>';
1457
1458
        preg_match_all('!<(title|description)>([^<]+)</\\1>!', $rss, $match);
1459
        next($match[2]);
1460
        next($match[2]);
1461
1462
        while (list(, $v) = each($match[2])) {
1463
            list(, $ver) = explode(' ', $v, 2);
1464
            if ($i < 0 && version_compare($apcversion, $ver, '>=')) {
1465
                break;
1466
            } elseif (!$i--) {
1467
                break;
1468
            }
1469
            echo "<b><a href=\"http://pecl.php.net/package/APC/$ver\">".htmlspecialchars($v, ENT_QUOTES, 'UTF-8')."</a></b><br><blockquote>";
1470
            echo nl2br(htmlspecialchars(current($match[2]), ENT_QUOTES, 'UTF-8'))."</blockquote>";
1471
            next($match[2]);
1472
        }
1473
        echo '</td></tr>';
1474
    }
1475
    echo <<< EOB
1476
        </tbody></table>
1477
        </div>
1478
EOB;
1479
    break;
1480
1481
}
1482
1483
echo <<< EOB
1484
    </div>
1485
EOB;
1486
1487
?>
1488
1489
<!-- <?php echo "\nBased on APCGUI By R.Becker\n$VERSION\n"?> -->
1490
</body>
1491
</html>
1492