Ignore:
Timestamp:
09/26/13 15:41:49 (11 years ago)
Author:
angelo
Message:

Ticket #3491 - Compatibilizar Expresso com novas versoes do PHP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/adodb-perf.inc.php

    r6057 r8222  
    11<?php 
    22/*  
    3 V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. 
     3V5.18 3 Sep 2012   (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. 
    44  Released under both BSD license and Lesser GPL library license.  
    55  Whenever there is any discrepancy between the two licenses,  
     
    2323define( 'ADODB_OPT_LOW', 1); 
    2424 
     25global $ADODB_PERF_MIN; 
     26$ADODB_PERF_MIN = 0.05; // log only if >= minimum number of secs to run 
     27 
     28 
    2529// returns in K the memory of current process, or 0 if not known 
    2630function adodb_getmem() 
     
    5458} 
    5559 
    56 /* return microtime value as a float */ 
     60/* obsolete: return microtime value as a float. Retained for backward compat */ 
    5761function adodb_microtime() 
    5862{ 
    59         $t = microtime(); 
    60         $t = explode(' ',$t); 
    61         return (float)$t[1]+ (float)$t[0]; 
     63        return microtime(true); 
    6264} 
    6365 
    6466/* sql code timing */ 
    65 function& adodb_log_sql(&$connx,$sql,$inputarr) 
     67function adodb_log_sql(&$connx,$sql,$inputarr) 
    6668{ 
    6769    $perf_table = adodb_perf::table(); 
    6870        $connx->fnExecute = false; 
    69         $t0 = microtime(); 
    70         $rs =& $connx->Execute($sql,$inputarr); 
    71         $t1 = microtime(); 
     71        $a0 = microtime(true); 
     72        $rs = $connx->Execute($sql,$inputarr); 
     73        $a1 = microtime(true); 
    7274 
    7375        if (!empty($connx->_logsql) && (empty($connx->_logsqlErrors) || !$rs)) { 
     
    7577         
    7678                if (!empty($ADODB_LOG_CONN)) { 
    77                         $conn = &$ADODB_LOG_CONN; 
     79                        $conn = $ADODB_LOG_CONN; 
    7880                        if ($conn->databaseType != $connx->databaseType) 
    7981                                $prefix = '/*dbx='.$connx->databaseType .'*/ '; 
     
    8183                                $prefix = ''; 
    8284                } else { 
    83                         $conn =& $connx; 
     85                        $conn = $connx; 
    8486                        $prefix = ''; 
    8587                } 
     
    8789                $conn->_logsql = false; // disable logsql error simulation 
    8890                $dbT = $conn->databaseType; 
    89                  
    90                 $a0 = preg_split('/ /',$t0); 
    91                 $a0 = (float)$a0[1]+(float)$a0[0]; 
    92                  
    93                 $a1 = preg_split('/ /',$t1); 
    94                 $a1 = (float)$a1[1]+(float)$a1[0]; 
    9591                 
    9692                $time = $a1 - $a0; 
     
    114110                if (isset($_SERVER['HTTP_HOST'])) { 
    115111                        $tracer .= '<br>'.$_SERVER['HTTP_HOST']; 
    116                         if (isset($_SERVER['PHP_SELF'])) $tracer .= $_SERVER['PHP_SELF']; 
     112                        if (isset($_SERVER['PHP_SELF'])) $tracer .= htmlspecialchars($_SERVER['PHP_SELF']); 
    117113                } else  
    118                         if (isset($_SERVER['PHP_SELF'])) $tracer .= '<br>'.$_SERVER['PHP_SELF']; 
     114                        if (isset($_SERVER['PHP_SELF'])) $tracer .= '<br>'.htmlspecialchars($_SERVER['PHP_SELF']); 
    119115                //$tracer .= (string) adodb_backtrace(false); 
    120116                 
     
    166162                        $isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $d,?,?,?,?,?)"; 
    167163                } 
    168                 $ok = $conn->Execute($isql,$arr); 
     164                 
     165                global $ADODB_PERF_MIN; 
     166                if ($errN != 0 || $time >= $ADODB_PERF_MIN) { 
     167                        $ok = $conn->Execute($isql,$arr); 
     168                } else 
     169                        $ok = true; 
     170                 
    169171                $conn->debug = $saved; 
    170172                 
     
    174176                        $err2 = $conn->ErrorMsg(); 
    175177                        $conn->_logsql = true; // enable logsql error simulation 
    176                         $perf =& NewPerfMonitor($conn); 
     178                        $perf = NewPerfMonitor($conn); 
    177179                        if ($perf) { 
    178180                                if ($perf->CreateLogTable()) $ok = $conn->Execute($isql,$arr); 
     
    228230         
    229231    // Sets the tablename to be used             
    230     function table($newtable = false) 
     232    static function table($newtable = false) 
    231233    { 
    232234        static $_table; 
     
    255257*/ 
    256258                // Algorithm is taken from 
    257                 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/example__obtaining_raw_performance_data.asp 
     259                // http://social.technet.microsoft.com/Forums/en-US/winservergen/thread/414b0e1b-499c-411e-8a02-6a12e339c0f1/ 
    258260                if (strncmp(PHP_OS,'WIN',3)==0) { 
    259261                        if (PHP_VERSION == '5.0.0') return false; 
     
    263265                        if (PHP_VERSION == '4.3.10') return false; # see http://bugs.php.net/bug.php?id=31737 
    264266                         
    265                         @$c = new COM("WinMgmts:{impersonationLevel=impersonate}!Win32_PerfRawData_PerfOS_Processor.Name='_Total'"); 
    266                         if (!$c) return false; 
    267                          
    268                         $info[0] = $c->PercentProcessorTime; 
    269                         $info[1] = 0; 
    270                         $info[2] = 0; 
    271                         $info[3] = $c->TimeStamp_Sys100NS; 
    272                         //print_r($info); 
     267                        static $FAIL = false; 
     268                        if ($FAIL) return false; 
     269                         
     270                        $objName = "winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2";       
     271                        $myQuery = "SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'"; 
     272                         
     273                        try { 
     274                                @$objWMIService = new COM($objName); 
     275                                if (!$objWMIService) { 
     276                                        $FAIL = true; 
     277                                        return false; 
     278                                } 
     279                 
     280                                $info[0] = -1; 
     281                                $info[1] = 0; 
     282                                $info[2] = 0; 
     283                                $info[3] = 0; 
     284                                foreach($objWMIService->ExecQuery($myQuery) as $objItem)  { 
     285                                                $info[0] = $objItem->PercentProcessorTime(); 
     286                                } 
     287                         
     288                        } catch(Exception $e) { 
     289                                $FAIL = true; 
     290                                echo $e->getMessage(); 
     291                                return false; 
     292                        } 
     293                         
    273294                        return $info; 
    274295                } 
     
    333354                $info = $this->_CPULoad(); 
    334355                if (!$info) return false; 
    335                          
    336                 if (empty($this->_lastLoad)) { 
    337                         sleep(1); 
     356                 
     357                if (strncmp(PHP_OS,'WIN',3)==0) { 
     358                        return (integer) $info[0]; 
     359                }else { 
     360                        if (empty($this->_lastLoad)) { 
     361                                sleep(1); 
     362                                $this->_lastLoad = $info; 
     363                                $info = $this->_CPULoad(); 
     364                        } 
     365                         
     366                        $last = $this->_lastLoad; 
    338367                        $this->_lastLoad = $info; 
    339                         $info = $this->_CPULoad(); 
    340                 } 
    341                  
    342                 $last = $this->_lastLoad; 
    343                 $this->_lastLoad = $info; 
    344                  
    345                 $d_user = $info[0] - $last[0]; 
    346                 $d_nice = $info[1] - $last[1]; 
    347                 $d_system = $info[2] - $last[2]; 
    348                 $d_idle = $info[3] - $last[3]; 
    349                  
    350                 //printf("Delta - User: %f  Nice: %f  System: %f  Idle: %f<br>",$d_user,$d_nice,$d_system,$d_idle); 
    351  
    352                 if (strncmp(PHP_OS,'WIN',3)==0) { 
    353                         if ($d_idle < 1) $d_idle = 1; 
    354                         return 100*(1-$d_user/$d_idle); 
    355                 }else { 
     368                         
     369                        $d_user = $info[0] - $last[0]; 
     370                        $d_nice = $info[1] - $last[1]; 
     371                        $d_system = $info[2] - $last[2]; 
     372                        $d_idle = $info[3] - $last[3]; 
     373                         
     374                        //printf("Delta - User: %f  Nice: %f  System: %f  Idle: %f<br>",$d_user,$d_nice,$d_system,$d_idle); 
     375                 
    356376                        $total=$d_user+$d_nice+$d_system+$d_idle; 
    357377                        if ($total<1) $total=1; 
     
    409429                $this->conn->fnExecute = false; 
    410430        $perf_table = adodb_perf::table(); 
    411                 $rs =& $this->conn->SelectLimit("select distinct count(*),sql1,tracer as error_msg from $perf_table where tracer like 'ERROR:%' group by sql1,tracer order by 1 desc",$numsql);//,$numsql); 
     431                $rs = $this->conn->SelectLimit("select distinct count(*),sql1,tracer as error_msg from $perf_table where tracer like 'ERROR:%' group by sql1,tracer order by 1 desc",$numsql);//,$numsql); 
    412432                $this->conn->fnExecute = $saveE; 
    413433                if ($rs) { 
     
    443463                        if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); 
    444464                        //$this->conn->debug=1; 
    445                         $rs =& $this->conn->SelectLimit( 
     465                        $rs = $this->conn->SelectLimit( 
    446466                        "select avg(timer) as avg_timer,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer 
    447467                                from $perf_table 
     
    522542                        if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); 
    523543                         
    524                         $rs =& $this->conn->SelectLimit( 
     544                        $rs = $this->conn->SelectLimit( 
    525545                        "select sum(timer) as total,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer 
    526546                                from $perf_table 
     
    571591                Raw function returning array of poll paramters 
    572592        */ 
    573         function &PollParameters() 
     593        function PollParameters() 
    574594        { 
    575595                $arr[0] = (float)$this->DBParameter('data cache hit ratio'); 
     
    641661        } 
    642662         
     663        function clearsql() 
     664        { 
     665                $perf_table = adodb_perf::table(); 
     666                $this->conn->Execute("delete from $perf_table where created<".$this->conn->sysTimeStamp); 
     667        } 
    643668        /***********************************************************************************************/ 
    644669        //                                    HIGH LEVEL UI FUNCTIONS 
     
    648673        function UI($pollsecs=5) 
    649674        { 
     675        global $ADODB_LOG_CONN; 
    650676         
    651677    $perf_table = adodb_perf::table(); 
     
    660686        $info = $conn->ServerInfo(); 
    661687        if (isset($_GET['clearsql'])) { 
    662                 $this->conn->Execute("delete from $perf_table"); 
     688                $this->clearsql(); 
    663689        } 
    664690        $this->conn->LogSQL($savelog); 
     
    689715         
    690716        $allowsql = !defined('ADODB_PERF_NO_RUN_SQL'); 
     717        global $ADODB_PERF_MIN; 
     718        $app .= " (Min sql timing \$ADODB_PERF_MIN=$ADODB_PERF_MIN secs)"; 
    691719         
    692720        if  (empty($_GET['hidem'])) 
     
    703731                default: 
    704732                case 'stats': 
     733                        if (empty($ADODB_LOG_CONN)) 
     734                                echo "<p>&nbsp; <a href=\"?do=viewsql&clearsql=1\">Clear SQL Log</a><br>"; 
    705735                        echo $this->HealthCheck(); 
    706736                        //$this->conn->debug=1; 
    707                         echo $this->CheckMemory(); 
     737                        echo $this->CheckMemory();               
    708738                        break; 
    709739                case 'poll': 
     740                        $self = htmlspecialchars($_SERVER['PHP_SELF']); 
    710741                        echo "<iframe width=720 height=80%  
    711                                 src=\"{$_SERVER['PHP_SELF']}?do=poll2&hidem=1\"></iframe>"; 
     742                                src=\"{$self}?do=poll2&hidem=1\"></iframe>"; 
    712743                        break; 
    713744                case 'poll2': 
     
    744775                if ($secs <= 1) $secs = 1; 
    745776                echo "Accumulating statistics, every $secs seconds...\n";flush(); 
    746                 $arro =& $this->PollParameters(); 
     777                $arro = $this->PollParameters(); 
    747778                $cnt = 0; 
    748779                set_time_limit(0); 
     
    750781                while (1) { 
    751782 
    752                         $arr =& $this->PollParameters(); 
     783                        $arr = $this->PollParameters(); 
    753784                         
    754785                        $hits   = sprintf('%2.2f',$arr[0]); 
     
    886917         
    887918                 
    888                 $PHP_SELF = $_SERVER['PHP_SELF']; 
     919                $PHP_SELF = htmlspecialchars($_SERVER['PHP_SELF']); 
    889920                $sql = isset($_REQUEST['sql']) ? $_REQUEST['sql'] : ''; 
    890921 
Note: See TracChangeset for help on using the changeset viewer.