<?php
class MyDate
{
public static function getcurrentDate()
{
static $current_date = '';
if (!$current_date) {
echo 'only run one time';
usleep(200000);
$current_date = date('Y-m-d H:i:s');
}
return $current_date;
}
public static function getCurrentDate2()
{
usleep(200000);
echo 'run everytime';
return date('Y-m-d H:i:s');
}
}
$start = microtime(true);
$i = 5;
while ($i--) {
MyDate::getCurrentDate();
}
echo microtime(true) - $start; //200ms
$start = microtime(true);
$i = 5;
while ($i--) {
MyDate::getCurrentDate2();
}
echo microtime(true) - $start; //1s
一个小技巧能提高不少性能
以上是脚本宝典为你收集整理的一个PHP的小技巧全部内容,希望文章能够帮你解决一个PHP的小技巧所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。