>  기사  >  백엔드 개발  >  PHP 코드 실행 시간 보기 클래스 코드 공유

PHP 코드 실행 시간 보기 클래스 코드 공유

高洛峰
高洛峰원래의
2016-11-30 11:19:30988검색

코드는 다음과 같습니다.
//date:2011-08-05
class RunTime//페이지 실행 시간 클래스
{
private $starttime;//페이지 시작 실행 시간
private $stoptime;//페이지 종료 실행 시간
private $spendtime;//소요된 페이지 실행 시간
function getmicrotime()//현재 마이크로초를 반환하는 부동 소수점 숫자 가져오기
{
list($ usec,$sec)=explode(" ",microtime());
return ((float)$usec + (float)$sec)
function start()/ /페이지 실행 시작 함수, 페이지가 실행된 시간을 반환
{
$this->starttime=$this->getmicrotime()
}
function end()/ /페이지가 실행된 시간 표시
{
$this->stoptime=$this->getmicrotime()
$this->spendtime=$this->stoptime-$ this->starttime
/ /return round($this->spendtime,10)
}
function display()
{
//$this->end ();
echo "< p>실행 시간: ".round($this->spendtime,10)."초

"
}
}
/* 호출 방법
$timer=new Runtime()
$timer->start();

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.