这个do_action()
和apply_filters()
都是
WP_Hook::apply_filters()
方法调用中注册的回调
sequential 订单号(
src).
Here\'s a simple test:
让我们定义一个回调包装器:
$callback_gen = function( $seconds ) {
return function() use ( $seconds ) {
sleep( $seconds );
printf( \'%s finished\' . PHP_EOL, $seconds );
};
};
接下来,我们将回调注册到
mytest
措施:
add_action( \'mytest\', $callback_gen( 3 ) );
add_action( \'mytest\', $callback_gen( 5 ) );
add_action( \'mytest\', $callback_gen( 1 ) );
然后调用回调并测量所需的时间:
$start = microtime( true );
do_action( \'mytest\' );
$stop = microtime( true );
并将其显示为:
echo number_format( $stop - $start, 5 );
以下是5次测试运行的输出:
3 finished
5 finished
1 finished
9.00087
3 finished
5 finished
1 finished
9.00076
3 finished
5 finished
1 finished
9.00101
3 finished
5 finished
1 finished
9.00072
3 finished
5 finished
1 finished
9.00080
其中每次运行的顺序相同,总时间为9秒,与连续运行顺序相同。