Location: PHPKode > projects > Netautor Professional > netautor/napro4/admin/database/perform/common.php
<?php
	/* @version $Revision: 1.3 $ */

	require_once('../../../include/init.inc');
	if(!$USER->check_feature('Admin') && !$USER->check_feature('ac_database'))
	{
		$USER->login_call();
	}

$FIELDS=	array	(	'CFG_DSN',			'CFG_TABLESPACE',
						'CFG_USER_NAME',	'CFG_USER_PASS',
						'CFG_DB_TYPE',		'CFG_STATEMENT',
						'CFG_PROFILE',		'CFG_PERSISTENT', 'SHOW_RESULT', 
						'CFG_REPETITIONS', 'CFG_NAME'	);
						
function showTimeProfile(&$times,$single_loop=false)
{
	echo('<br>Startet at <b>'.date('d.m.Y H:i:s',$times['meta']['start']).'</b><br>');
	echo('Finished at <b>'.date('d.m.Y H:i:s',$times['meta']['end']).'</b><br>');
	echo('Duration approx. <b>'.($times['meta']['end']-$times['meta']['start']).' second(s) </b><br>');

	$times['max']['connect']		=	0;	$times['max']['read']			=	0;
	$times['max']['query']			=	0;	$times['max']['disconnect']		=	0;

	$times['avg']['connect']		=	0;	$times['avg']['read']			=	0;
	$times['avg']['query']			=	0;	$times['avg']['disconnect']		=	0;

	$times['sum']['connect']		=	0;	$times['sum']['read']			=	0;
	$times['sum']['query']			=	0;	$times['sum']['disconnect']		=	0;

	$times['min']['connect']		=	100000;	$times['min']['read']			=	100000;
	$times['min']['query']			=	100000;	$times['min']['disconnect']		=	100000;
	

	foreach ($times['connect'] as $index	=> $data)
	{
		keepConnect();
		$times['operation'][$index]['sum'] = 0.0;
		if ($single_loop) echo	"<br><font class='title'>Loop	: ".($index+1)."</font><br>";
		
		$duration	=	$data['b'] - $data['a'];
		if ($single_loop) echo	"<font class='time'>Open&nbsp;&nbsp;:&nbsp;$duration</font><br>";

		if ($duration < $times['min']['connect'])  $times['min']['connect'] = $duration;
		if ($duration > $times['max']['connect'])  $times['max']['connect'] = $duration;
		$times['sum']['connect']+= $duration;

		$times['operation'][$index]['sum']+=$duration;

		$data		= $times['query'][$index];
		$duration	=	$data['b'] - $data['a'];
		if ($single_loop) echo	"<font class='time'>Query&nbsp;:&nbsp;$duration</font><br>";
		if ($duration < $times['min']['query'])  $times['min']['query'] = $duration;
		if ($duration > $times['max']['query'])  $times['max']['query'] = $duration;
		$times['sum']['query']+= $duration;
		$times['operation'][$index]['sum']+=$duration;

		$data		= $times['read'][$index];
		$duration	=	$data['b'] - $data['a'];
		if ($single_loop) echo	"<font class='time'>Read&nbsp;&nbsp;:&nbsp;$duration</font><br>";
		if ($duration < $times['min']['read'])  $times['min']['read'] = $duration;
		if ($duration > $times['max']['read'])  $times['max']['read'] = $duration;
		$times['sum']['read']+= $duration;
		$times['operation'][$index]['sum']+=$duration;

		$data		= $times['disconnect'][$index];
		$duration	=	$data['b'] - $data['a'];
		if ($single_loop) echo	"<font class='time'>Close&nbsp;:&nbsp;$duration</font><br>";
		if ($duration < $times['min']['disconnect'])  $times['min']['disconnect'] = $duration;
		if ($duration > $times['max']['disconnect'])  $times['max']['disconnect'] = $duration;
		$times['sum']['disconnect']+= $duration;
		$times['operation'][$index]['sum']+=$duration;

	}
	$times['avg']['connect']	= $times['sum']['connect'] / $times['meta']['config']['CFG_REPETITIONS'];
	$times['avg']['query']		= $times['sum']['query'] / $times['meta']['config']['CFG_REPETITIONS'];
	$times['avg']['read']		= $times['sum']['read'] / $times['meta']['config']['CFG_REPETITIONS'];
	$times['avg']['disconnect']	= $times['sum']['disconnect'] / $times['meta']['config']['CFG_REPETITIONS'];

?>
	<br>
	<table border="1" cellspacing="0" cellpadding="2" width="100%">	
		<tr>
			<td class="title">DB Type</td>
			<td class="title">PHP Version</td>
			<td class="title">OS</td>
			<td class="title">SAPI</td>
			<td class="title">Optimizer</td>
			<td class="title">Cache</td>			
		</tr>
		<tr>
			<td  class="time"><?php echo $times['meta']['config']['CFG_DB_TYPE'];?></td>			
			<td  class="time"><?php echo $times['meta']['env']['php'];?></td>
			<td  class="time"><?php echo $times['meta']['env']['os'];?></td>
			<td  class="time"><?php echo $times['meta']['env']['sapi'];?></td>
			<td  class="time"><?php echo $times['meta']['env']['optimizer'];?></td>
			<td  class="time"><?php echo $times['meta']['env']['cache'];?></td>
		</tr>
	</table>
	<br>	
	<table border="1" cellspacing="0" cellpadding="2" width="100%">
		<tr>
			<td class="text">in seconds</td>
			<td class="title">MIN</td>
			<td class="title">MAX</td>
			<td class="title">AVG</td>
			<td class="title">SUM</td>
		</tr>
		<tr>
			<td class="title">Open</td>
			<td class="time"><?php echo formatTime($times['min']['connect']);?></td>
			<td class="time"><?php echo formatTime($times['max']['connect']);?></td>
			<td class="time"><?php echo formatTime($times['avg']['connect']);?></td>
			<td class="time"><?php echo formatTime($times['sum']['connect']);?></td>
		</tr>
		<tr>
			<td class="title">Query</td>
			<td class="time"><?php echo formatTime($times['min']['query']);?></td>
			<td class="time"><?php echo formatTime($times['max']['query']);?></td>
			<td class="time"><?php echo formatTime($times['avg']['query']);?></td>
			<td class="time"><?php echo formatTime($times['sum']['query']);?></td>
		</tr>
		<tr>
			<td class="title">Read</td>
			<td class="time"><?php echo formatTime($times['min']['read']);?></td>
			<td class="time"><?php echo formatTime($times['max']['read']);?></td>
			<td class="time"><?php echo formatTime($times['avg']['read']);?></td>
			<td class="time"><?php echo formatTime($times['sum']['read']);?></td>
		</tr>
		<tr>
			<td class="title">Close</td>
			<td class="time"><?php echo formatTime($times['min']['disconnect']);?></td>
			<td class="time"><?php echo formatTime($times['max']['disconnect']);?></td>
			<td class="time"><?php echo formatTime($times['avg']['disconnect']);?></td>
			<td class="time"><?php echo formatTime($times['sum']['disconnect']);?></td>
		</tr>
<?php 
	$times['operations']['min'] = 1.0;
	$times['operations']['max'] = 0.0;
	$times['operations']['avg'] = 0.0;
	$times['operations']['sum'] = 0.0;

	
	$max_ops = 0;
	foreach ($times['operation'] as $index	=> $data)
	{
		if (is_null($data['sum'])) continue;
		$max_ops++;
		$value	= $data['sum'];
		
		$times['operations']['sum']+=$value;
		$times['operations']['min']	= min ($value,$times['operations']['min']);
		$times['operations']['max']	= max ($value,$times['operations']['max']);
		keepConnect();
	}
		$times['operations']['avg'] = 	$times['operations']['sum'] / $max_ops;
	
?>
		<tr>
			<td height="1" colspan="5"></td>
		</tr>
		<tr>
			<td class="title">Operation</td>
			<td class="time"><?php echo formatTime($times['operations']['min']);?></td>
			<td class="time"><?php echo formatTime($times['operations']['max']);?></td>
			<td class="time"><?php echo formatTime($times['operations']['avg']);?></td>
			<td class="time"><?php echo formatTime($times['operations']['sum']);?></td>
		</tr>
	</table>
	<?php 
}

function getmicrotime()
{
	list($usec, $sec) = explode(' ',microtime());
	return ((float)$usec + (float)$sec);
}

function keepConnect(){
	echo "<!--//-->";flush();
	@set_time_limit(0);
}

function formatTime($time){
	return number_format($time,10,',','.');
}
?>
Return current item: Netautor Professional