Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- ocp.php.orig Mon Sep 23 15:51:24 2013
- +++ ocp.php Mon Sep 23 15:57:16 2013
- @@ -31,23 +31,41 @@
- */
- // ini_set('display_errors',1); error_reporting(-1);
- -if ( count(get_included_files())>1 || php_sapi_name()=='cli' || empty($_SERVER['REMOTE_ADDR']) ) { die; } // weak block against indirect access
- +$max_included_files = 1;
- +if ( ini_get('auto_prepend_file') ) ++$max_included_files;
- +if ( count(get_included_files())>$max_included_files || getcwd() != dirname(__FILE__) || php_sapi_name()=='cli' || empty($_SERVER['REMOTE_ADDR']) ) { die; } // weak block against indirect access
- $time=time();
- define('CACHEPREFIX',function_exists('opcache_reset')?'opcache_':(function_exists('accelerator_reset')?'accelerator_':''));
- +function ocp_function_exists($function_name)
- +{
- + if ( CACHEPREFIX == '' ) {
- + return false;
- + }
- + return function_exists(CACHEPREFIX.$function_name);
- +}
- +
- +function ocp_call_user_func($function_name)
- +{
- + if ( CACHEPREFIX == '' ) {
- + return false;
- + }
- + return call_user_func(CACHEPREFIX.$function_name);
- +}
- +
- if ( !empty($_GET['RESET']) ) {
- - if ( function_exists(CACHEPREFIX.'reset') ) { call_user_func(CACHEPREFIX.'reset'); }
- + if ( ocp_function_exists('reset') ) { ocp_call_user_func('reset'); }
- header( 'Location: '.str_replace('?'.$_SERVER['QUERY_STRING'],'',$_SERVER['REQUEST_URI']) );
- exit;
- }
- if ( !empty($_GET['RECHECK']) ) {
- - if ( function_exists(CACHEPREFIX.'invalidate') ) {
- - $recheck=trim($_GET['RECHECK']); $files=call_user_func(CACHEPREFIX.'get_status');
- + if ( ocp_function_exists('invalidate') ) {
- + $recheck=trim($_GET['RECHECK']); $files=ocp_call_user_func('get_status');
- if (!empty($files['scripts'])) {
- foreach ($files['scripts'] as $file=>$value) {
- - if ( $recheck==='1' || strpos($file,$recheck)===0 ) call_user_func(CACHEPREFIX.'invalidate',$file);
- + if ( $recheck==='1' || strpos($file,$recheck)===0 ) ocp_call_user_func('invalidate',$file);
- }
- }
- header( 'Location: '.str_replace('?'.$_SERVER['QUERY_STRING'],'',$_SERVER['REQUEST_URI']) );
- @@ -117,7 +135,7 @@
- <a href="?ALL=1">Details</a>
- <a href="?FILES=1&GROUP=2&SORT=3">Files</a>
- <a href="?RESET=1" onclick="return confirm('RESET cache ?')">Reset</a>
- - <?php if ( function_exists(CACHEPREFIX.'invalidate') ) { ?>
- + <?php if ( ocp_function_exists('invalidate') ) { ?>
- <a href="?RECHECK=1" onclick="return confirm('Recheck all files in the cache ?')">Recheck</a>
- <?php } ?>
- <a href="?" onclick="window.location.reload(true); return false">Refresh</a>
- @@ -125,7 +143,7 @@
- <?php
- -if ( !function_exists(CACHEPREFIX.'get_status') ) { echo '<h2>Opcache not detected?</h2>'; die; }
- +if ( !ocp_function_exists('get_status') ) { echo '<h2>Opcache not detected?</h2>'; die; }
- if ( !empty($_GET['FILES']) ) { echo '<h2>files cached</h2>'; files_display(); echo '</div></body></html>'; exit; }
- @@ -134,7 +152,7 @@
- ob_start(); phpinfo(8); $phpinfo = ob_get_contents(); ob_end_clean(); // some info is only available via phpinfo? sadly buffering capture has to be used
- if ( !preg_match( '/module\_Zend (Optimizer\+|OPcache).+?(\<table[^>]*\>.+?\<\/table\>).+?(\<table[^>]*\>.+?\<\/table\>)/s', $phpinfo, $opcache) ) { } // todo
- -if ( function_exists(CACHEPREFIX.'get_configuration') ) { echo '<h2>general</h2>'; $configuration=call_user_func(CACHEPREFIX.'get_configuration'); }
- +if ( ocp_function_exists('get_configuration') ) { echo '<h2>general</h2>'; $configuration=ocp_call_user_func('get_configuration'); }
- $host=function_exists('gethostname')?@gethostname():@php_uname('n'); if (empty($host)) { $host=empty($_SERVER['SERVER_NAME'])?$_SERVER['HOST_NAME']:$_SERVER['SERVER_NAME']; }
- $version=array('Host'=>$host);
- @@ -144,7 +162,7 @@
- if ( !empty($opcache[2]) ) { echo preg_replace('/\<tr\>\<td class\="e"\>[^>]+\<\/td\>\<td class\="v"\>[0-9\,\. ]+\<\/td\>\<\/tr\>/','',$opcache[2]); }
- -if ( function_exists(CACHEPREFIX.'get_status') && $status=call_user_func(CACHEPREFIX.'get_status') ) {
- +if ( ocp_function_exists('get_status') && $status=ocp_call_user_func('get_status') ) {
- $uptime=array();
- if ( !empty($status[CACHEPREFIX.'statistics']['start_time']) ) {
- $uptime['uptime']=time_since($time,$status[CACHEPREFIX.'statistics']['start_time'],1,'');
- @@ -257,7 +275,7 @@
- }
- function files_display() {
- - $status=call_user_func(CACHEPREFIX.'get_status');
- + $status=ocp_call_user_func('get_status');
- if ( empty($status['scripts']) ) {return;}
- if ( isset($_GET['DUMP']) ) { print_table($status['scripts']); exit;}
- $time=time(); $sort=0;
- @@ -338,8 +356,8 @@
- $graphs=array();
- $colors=array('green','brown','red');
- $primes=array(223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987);
- - $configuration=call_user_func(CACHEPREFIX.'get_configuration');
- - $status=call_user_func(CACHEPREFIX.'get_status');
- + $configuration=ocp_call_user_func('get_configuration');
- + $status=ocp_call_user_func('get_status');
- $graphs['memory']['total']=$configuration['directives']['opcache.memory_consumption'];
- $graphs['memory']['free']=$status['memory_usage']['free_memory'];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement