大家可通常用的microtime()获取页面开始和结束时的时间并相减的话,计算结果是页面运行 所经历的一段时间,但这并不一定是该页面自身运行的时间
实例代码如下:
- <?php
- //实例:计算页面运行时加载时间
- //分析:页面打开时获取一个时间,加载完成时获取一个时间,运行时间即二者之差
- //1.自定义函数
- function fn(){
- list($a,$b) = explode(' ',microtime()); //获取并分割当前时间戳和微妙数,赋值给变量
- return $a+$b;
- }
- //2.获取开始时间
- $start_time = fn();
- //5.加载过程
- for($i=0;$i<10000000;$i++){
- // do nothing;
- }
- //3.获取结束时间
- $end_time = fn();
- //4.计算差值
- echo $end_time–$start_time;
- //5.格式化输出
- echo '<br />';
- $t = $end_time–$start_time;
- echo round($t,2);
- ?>
使用microtime()获取页面开始和结束时的时间并相减的话,计算结果是页面运行
所经历的一段时间,但这并不一定是该页面自身运行的时间.因为可能存在多个PHP脚
本页面共同执行的情况,所以我觉得那个方法是不准确的
下面从网上找到一个关于php中计算页面程序运行时间的实例有需要的朋友可参考一下.
最近写了一个程序运行的时间计算类,供大家参考:
实例代码如下:
- class Timer {
- private $StartTime = 0;//程序运行开始时间
- private $StopTime = 0;//程序运行结束时间
- private $TimeSpent = 0;//程序运行花费时间
- function start(){//程序运行开始
- $this->StartTime = microtime();
- }
- function stop(){//程序运行结束
- $this->StopTime = microtime();
- }
- function spent(){//程序运行花费的时间
- if ($this->TimeSpent) {
- return $this->TimeSpent;
- } else {
- list($StartMicro, $StartSecond) = explode(" ", $this->StartTime);
- list($StopMicro, $StopSecond) = explode(" ", $this->StopTime);
- $start = doubleval($StartMicro) + $StartSecond;
- $stop = doubleval($StopMicro) + $StopSecond;
- $this->TimeSpent = $stop – $start;
- return substr($this->TimeSpent,0,8)."秒";//返回获取到的程序运行时间差
- }
- }
- }
- $timer = new Timer();
- $timer->start();
- //…程序运行的代码
- $timer->stop();
- echo "程序运行时间为:".$timer->spent();
再看简化程序 计算页面加载时间
实例代码如下:
- <?php
- class runtime
- {
- var $StartTime = 0;
- var $StopTime = 0;
- function get_microtime()
- {
- list($usec, $sec) = explode(' ', microtime());
- return ((float)$usec (float)$sec);
- }
- function start()
- {
- $this->StartTime = $this->get_microtime();
- }
- function stop()
- {
- $this->StopTime = $this->get_microtime();
- }
- function spent()
- {
- return round(($this->StopTime – $this->StartTime) * 1000, 1);
- }
- }
- //实例开始
- $runtime= new runtime;
- $runtime->start();
- //你的代码开始
- $a = 0;
- for($i=0; $i<1000000; $i )
- {
- $a = $i;
- }
- //你的代码结束
- $runtime->stop();
- echo "页面执行时间: ".$runtime->spent()." 毫秒";
- ?>
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » php中计算页面加载时间几种方法总结
波比源码 » php中计算页面加载时间几种方法总结
buy levofloxacin 250mg online cheap order levofloxacin without prescription
arimidex for sale Canadian healthcare viagra sales order sildenafil 50mg
tadalafil sans ordonnance acheter 20mg tadalafil pharmacie en ligne sildenafil
catapres cheap clonidine 0.1 mg brand spiriva 9 mcg usa
buy generic buspirone 10mg phenytoin 100 mg cost ditropan 5mg pills
zyban 150mg without prescription strattera for sale buy generic quetiapine 50mg
sertraline 100mg pills lexapro price sildenafil 100mg over the counter
order imuran 100 mcg generic sildenafil otc sildenafil pharmacy
viagra cialis buy clomipramine 50mg generic clomipramine 50mg for sale
sporanox 100mg generic itraconazole uk buy tindamax generic
glycomet 1000mg us buy metformin 500mg for sale tadalafil dosage
order generic levitra buy pregabalin 150mg pills methylprednisolone 4mg tablets
clomiphene order purchase ventolin inhalator for sale free online slots
order tadalafil 5mg without prescription cheap sildenafil 50mg buy viagra 100mg online
order generic cialis order sildenafil 50mg online cheap sildenafil pills 25mg
buy baclofen online cheap buy zanaflex toradol tablet
real money casino games casino games online real money best online casino for money
cialis 5mg uk buy cipro 1000mg without prescription buy generic cipro 1000mg
purchase simvastatin valacyclovir buy online order propecia 5mg sale
flagyl 400mg sale order bactrim 960mg pill trimethoprim pill
purchase viagra sale viagra 100mg uk order tadalafil online cheap
online gambling real money free roulette online real cialis
buy trazodone generic buy trazodone 100mg cheap aurogra 50mg
fildena cost sildenafil 100mg pill rhinocort allergy nasal spray
retin over the counter order avanafil 100mg sale avanafil drug
order cialis 40mg generic vegas casino online online casino game
ivermectin 3 mg over the counter dapsone 100 mg us oral dapsone 100 mg
nifedipine tablet perindopril oral generic fexofenadine
altace generic buy glimepiride 1mg for sale order arcoxia 60mg pill
buy mesalamine 800mg pills generic astelin 10 ml irbesartan oral
buy olmesartan online cheap depakote 250mg drug divalproex tablet
buy diamox 250 mg for sale imdur 20mg canada order imuran 50mg without prescription
buy generic digoxin 250 mg order generic telmisartan 80mg molnupiravir order online
coreg 25mg pills elavil buy online order amitriptyline pills
amoxil medication amoxil 250mg sale ivermectin 12 mg for humans for sale
priligy 60mg sale buy dapoxetine 90mg without prescription domperidone without prescription
pamelor us buy panadol pills buy generic paroxetine 20mg
famotidine tablet buy tacrolimus 5mg generic remeron us
fenofibrate uk sildenafil 100 mg buy sildenafil 50mg pill
buy minocin generic buy generic terazosin purchase hytrin without prescription
sildenafil 50mg oral finasteride 1mg sale order propecia 5mg
isotretinoin 40mg oral accutane 10mg generic ampicillin 250mg drug
buy ondansetron 4mg online amoxicillin cheap generic trimethoprim
albuterol 4mg usa synthroid 75mcg drug augmentin 375mg cost
order accutane 20mg pill order amoxicillin 1000mg sale buy generic zithromax 250mg
modafinil canada provigil order generic lopressor 50mg
buy dutasteride without prescription avodart cost xenical 120mg over the counter
doxycycline 100mg canada order acyclovir generic cost acyclovir 400mg
brand imuran 25mg order naproxen 500mg pill order naproxen
cefdinir 300mg cost cost prevacid order pantoprazole 20mg for sale
sildenafil citrate buy cialis online cheap buy tadalafil 5mg generic
levofloxacin 500mg us bupropion over the counter purchase zyban without prescription
order warfarin 2mg generic order zyloprim 100mg for sale zyloprim 300mg pills
buy lexapro online cheap fluoxetine order where can i buy naltrexone
tadalafil cialis buy branded cialis buy ed medication
how to buy modafinil cheap prednisone 10mg buy prednisone for sale
doxycycline generic augmentin 375mg canada augmentin 1000mg us
order methotrexate sale reglan 20mg cost metoclopramide pills
orlistat price order xenical 60mg pill order allopurinol 300mg generic
how to buy cozaar topamax order online buy topamax 100mg
buy crestor 20mg online generic crestor buy motilium tablets
order sumatriptan 50mg online order levaquin 500mg sale purchase avodart without prescription
buy sumycin 250mg online order sumycin 250mg generic purchase ozobax online
order toradol 10mg online cheap order inderal 10mg pill buy inderal paypal
purchase progesterone online cheap olanzapine zyprexa 10mg oral
buy zocor 20mg generic viagra buy online order sildenafil 100mg
purchase cialis generic mail viagra sildenafil 50mg tablet
purchase duricef pills buy combivir pills buy finasteride 5mg
diflucan 100mg uk acillin oral order cipro without prescription
buy metronidazole 400mg generic where can i buy flagyl cephalexin 250mg usa
buy generic nolvadex nolvadex without prescription purchase cefuroxime for sale
indocin 50mg over the counter indocin 75mg pill cefixime generic
purchase suhagra for sale buy generic suhagra over the counter sildalis canada
purchase azipro online cheap azipro 500mg uk cheap gabapentin pills
lasix online buy lasix 100mg oral brand ventolin
generic vardenafil vardenafil 10mg for sale buy hydroxychloroquine generic
asacol 400mg drug astelin us buy cheap avapro
vardenafil price hydroxychloroquine 200mg for sale buy generic hydroxychloroquine 200mg
purchase temovate generic buy clobetasol without prescription how to get cordarone without a prescription
digoxin online buy buy generic molnunat online molnupiravir 200mg ca
cheap carvedilol cenforce 100mg us order chloroquine 250mg without prescription
albuterol 100 mcg pills order albuterol pills order pyridium 200 mg pills
order montelukast 10mg online cheap how to buy symmetrel avlosulfon for sale online
order baricitinib 2mg online cheap buy atorvastatin without a prescription lipitor 20mg generic
buy nifedipine 30mg without prescription allegra canada fexofenadine price
oral dapoxetine 60mg buy dapoxetine for sale orlistat usa
brand crestor order ezetimibe without prescription motilium uk
oral sumycin 500mg baclofen order purchase lioresal for sale
order ampicillin 500mg generic buy ampicillin flagyl price
buy toradol 10mg generic buy inderal 10mg purchase inderal for sale
bactrim 960mg pills order keflex online cheap buy generic cleocin for sale
purchase plavix pills methotrexate order warfarin 2mg for sale
buy erythromycin 500mg for sale tamoxifen 10mg drug where to buy nolvadex without a prescription
metoclopramide order buy nexium 20mg online cheap generic nexium 20mg
purchase methocarbamol pill desyrel 100mg pill sildenafil 50mg cost
aurogra 100mg generic order sildalis generic buy estrace 1mg online cheap
celebrex over the counter flomax 0.4mg tablet ondansetron 4mg cost
buy generic lamictal how to buy mebendazole order prazosin 1mg pill
tadacip 20mg drug indomethacin order indomethacin 50mg tablet
tadalafil order natural pills for erectile dysfunction sexual dysfunction
terbinafine ca buy generic trimox amoxicillin 250mg cost
generic azulfidine 500 mg olmesartan 10mg ca calan 120mg sale
anastrozole 1mg oral arimidex 1 mg oral order catapres pill
molnupiravir 200 mg pill order naproxen cefdinir 300 mg brand
over the counter erectile dysfunction pills cheap viagra generic viagra for men
cost prevacid 15mg buy albuterol 100 mcg online order pantoprazole generic
mens erection pills buy tadalafil 10mg online cheap cialis walmart
buy avlosulfon sale order dapsone 100mg generic buy aceon online
best place to buy ed pills online overnight delivery for cialis tadalafil 40mg uk
fexofenadine 120mg over the counter fexofenadine 180mg uk generic amaryl 1mg
cordarone for sale carvedilol 6.25mg uk buy phenytoin 100mg generic
buy ditropan 2.5mg alendronate drug alendronate online buy
order glucotrol online cheap glipizide 5mg price order betamethasone 20gm online
panadol 500mg uk panadol over the counter famotidine medication
order tacrolimus for sale cost remeron purchase requip online cheap
diovan 80mg us purchase valsartan purchase ipratropium pill
oxcarbazepine 600mg canada uroxatral 10 mg tablet urso us
buy captopril 25mg for sale buy captopril 25mg buy carbamazepine 400mg without prescription
ciplox pills buy lincocin 500 mg online buy duricef for sale
order combivir online cost zidovudine accupril 10 mg cheap
order sarafem for sale purchase letrozole online cheap order letrozole 2.5 mg sale
buy bisoprolol 5mg buy generic oxytetracycline order terramycin