本文目錄一覽:
如何用php計算代碼執行的時間函數
php中缺省的最長執行時間是 30 秒,這是由 php.ini 中的 max_execution_time 變量指定,倘若你有一個需要頗多時間才能完成的工作,例如要發送很多電子郵件給大量收件者,或者要進行繁重的數據分析工作,服務器會在 30 秒後強行中止正在執行的程序。
設置的辦法是:
一、直接修改php.ini 中 max_execution_time 的數值。
二、在沒權限修改php.ini文件時,在 PHP 程序中加入 ini_set(‘max_execution_time’, ‘0’),數值 0 表示沒有執行時間的限制。
如何用php獲取程序執行的時間
在文件頭加入$stime=microtime(true);
在文件尾加入
$etime=microtime(true);//獲取程序執行結束的時間
$total=$etime-$stime; //計算差值
echo “br /[頁面執行時間:{$total} ]秒”;
例如
文件頭
?php
$stime=microtime(true);
?
文件尾
?php
$etime=microtime(true);//獲取程序執行結束的時間
$total=$etime-$stime; //計算差值
echo “br /[頁面執行時間:{$total} ]秒”;
這樣就可以計算出整個PHP頁面執行的時間。純手打,望採納。
php 如何計算時間
php計算時間的應用主要有如下幾個:
echo “br***************用PHP打印出前一天的時間***************br”;
echo date(“Y-m-d “,strtotime(” -1 day”));//昨天
echo ‘br’;
echo date(“Y-m-d “,strtotime(” +1 day”)); //明天
echo “br********************輸出當前時間*********************br”;
echo date(“Y年m月d日 l H:i:s A”); //2011年08月29日 Monday 04:52:25 AM
echo ‘br’;
echo date(“y-n-j D h:i:s a”); //11-8-29 Mon 04:52:25 am
echo ‘br’;
echo date(“Y年n月j日 l G:i:s a”,strtotime(“now”));//2011年8月29日 Monday 7:56:05 am
echo “br*****************兩個日期之間的天數******************br”;
$str1=strtotime(“2007-02-08”);
$str2=strtotime(“now”);
print_r (floor(($str2-$str1)/(3600*24)));
echo “br**********************倒計時*************************br”;
$time1=strtotime(“2012-7-18 17:30:00”);
$time2=strtotime(“now”);
$sec=$time1-$time2;
$year=floor($sec/3600/24/365);//年
$temp=$sec-$year*365*24*3600;
$month=floor($temp/3600/24/30);//月
$temp=$temp-$month*30*24*3600;
$day=floor($temp/3600/24);//日
$temp=$temp-$day*3600*24;
$hour=floor($temp/3600);//小時
$temp=$temp-$hour*3600;
$minute=floor($temp/60);//分
$second=$temp-$minute*60;//秒
echo “距離培訓畢業還有”.$year.”年”.$month.”月”.$day.”天”.$hour.”小時”.$minute.”分”.$second.”秒”;
php 如何判斷執行時間
要計算代碼的執行時間,在PHP來講是十分簡單的,首先,你需要知道,PHP是一種順序執行的腳本語言,所以,可以按照以下步驟來計算代碼的執行時間:
?php
function getmicrotime()
{
list($usec, $sec) = explode(” “,microtime());
return ((float)$usec + (float)$sec);
}
// 記錄開始時間
$time_start = getmicrotime();
// 這裡放要執行的PHP代碼,如:
// echo create_password(6);
// 記錄結束時間
$time_end = getmicrotime();
$time = $time_end – $time_start;
// 輸出運行總時間
echo “執行時間 $time seconds”;
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/254228.html