php里的declare用法


function tick_handler ()
{
echo "tick_handler() called<br>" ;
}
function tick_handler1 ()
{
echo "tick_handler1() called<br>" ;
}


register_tick_function ( ‘tick_handler‘ );
register_tick_function ( ‘tick_handler1‘ );

declare( ticks = 1 ){
$a = 1 ;

if ( $a > 0 ) {
$a += 2 ;
print( $a );
}
}
exit;

这里首先定义了两个函数,然后注册到系统,随后通过declare定义一个ticks,步长为1,作用是在declare作用域中的代码每执行ticks次步长,就执行一次注册的方法,方法顺与注册的顺序一致。

所以上面的执行结果是:

tick_handler() called
tick_handler1() called
tick_handler() called
tick_handler1() called
3tick_handler() called
tick_handler1() called
tick_handler() called
tick_handler1() called
tick_handler() called
tick_handler1() called
tick_handler() called
tick_handler1() called

这个方法可以测试执行代码的处理时间。

php里的declare用法,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。