@@ -95,6 +95,26 @@ function human_size( $s ) {
9595 return $ s . ' ' . $ size ;
9696 }
9797
98+ function machine_size ( $ val ) {
99+ $ val = trim ($ val );
100+ $ last = strtolower ($ val [strlen ($ val )-1 ]);
101+
102+ if (!is_numeric ($ last )){
103+ $ val = (int ) substr ($ val , 0 , -1 );
104+ }
105+
106+ switch ($ last ) {
107+ case 'g ' :
108+ $ val *= 1024 ;
109+ case 'm ' :
110+ $ val *= 1024 ;
111+ case 'k ' :
112+ $ val *= 1024 ;
113+ }
114+
115+ return $ val ;
116+ }
117+
98118 function redirect ($ url ) {
99119 header ('Status: 302 Moved Temporarily ' );
100120 header ('Location: ' . $ url );
@@ -174,6 +194,11 @@ function sort_list(&$list) {
174194 apcu_delete ( new ApcuIterator (get_selector ()) );
175195 redirect ( '?action=apcu_select&selector= ' . $ _GET ['selector ' ] );
176196 }
197+
198+ if ( isset ( $ _GET ['action ' ] ) && $ _GET ['action ' ] == 'realpath_clear ' ) {
199+ clearstatcache (true );
200+ redirect ('?#realpath ' );
201+ }
177202?> <html>
178203 <head>
179204 <title>Cache Status</title>
@@ -194,6 +219,7 @@ function sort_list(&$list) {
194219 table th { background: #686868; color: white; padding: 0.5em 1em 0.2em 1em; font-weight: normal; }
195220 table th a { text-decoration: none; color: white; cursor: pointer; }
196221 table tr:nth-child(2n+1) { background: #efefef; }
222+
197223 @media screen and (max-width: 480px) {
198224 input { width: 40%; }
199225 }
@@ -203,7 +229,7 @@ function sort_list(&$list) {
203229 <body>
204230 <div class="wrap">
205231 <div>
206- Goto: <a href="#opcache">PHP Opcache</a> or <a href="#apcu"><?= $ apcVersion?> </a>
232+ Goto: <a href="#opcache">PHP Opcache</a> or <a href="#apcu"><?= $ apcVersion?> </a> or <a href="#realpath">Realpath</a>
207233 </div>
208234 <h2 id="opcache">PHP Opcache</h2>
209235 <div>
@@ -343,6 +369,55 @@ function sort_list(&$list) {
343369 </table>
344370 </div>
345371 <?php endif ; ?>
372+
373+ <h2 id="realpath">Realpath</h2>
374+ <div>
375+ <?php
376+ $ realpathCacheUsed = realpath_cache_size ();
377+ $ realpathCacheTotal = machine_size (ini_get ('realpath_cache_size ' ));
378+ ?>
379+ <h3>Memory <?= human_size ($ realpathCacheUsed )?> of <?= human_size ($ realpathCacheTotal )?> </h3>
380+ <div class="full bar green">
381+ <div class="orange" style="width: <?= percentage ($ realpathCacheUsed , $ realpathCacheTotal )?> %"></div>
382+ </div>
383+ <div>
384+ <h3>Actions</h3>
385+ <form action="?" method="GET">
386+ <button type="submit" name="action" value="realpath_clear">Clear</button>
387+ </form>
388+ <form action="?" method="GET">
389+ <button type="submit" name="action" value="realpath_show">Show</button>
390+ </form>
391+ </div>
392+
393+ <?php if ( isset ( $ _GET ['action ' ] ) && $ _GET ['action ' ] == 'realpath_show ' ): ?>
394+ <div>
395+ <table>
396+ <thead>
397+ <tr>
398+ <th>Path</th>
399+ <th>Is Directory</a></th>
400+ <th>Realpath</th>
401+ <th>Expires</th>
402+ <th>Key</th>
403+ </tr>
404+ </thead>
405+
406+ <tbody>
407+ <?php foreach ( realpath_cache_get () as $ path => $ item ): ?>
408+ <tr>
409+ <td><?php echo $ path ;?> </td>
410+ <td><?php echo $ item ['is_dir ' ] ? '✔ ' : '' ?> </td>
411+ <td><?php echo $ item ['realpath ' ];?> </td>
412+ <td><?php echo date ('Y-m-d H:i:s ' , $ item ['expires ' ]);?> </td>
413+ <td><?php echo sprintf ('%u ' , $ item ['key ' ]);?> </td>
414+ </tr>
415+ <?php endforeach ; ?>
416+ </tbody>
417+ </table>
418+ </div>
419+ <?php endif ; ?>
420+ </div>
346421 </div>
347422 </body>
348423</html>
0 commit comments