Php 如何为所有函数设置勾号_func()?

Php 如何为所有函数设置勾号_func()?,php,Php,如何设置所有函数的勾选功能 function tick_func(){ //for all func, sleep(1); } //sample function call_any_func(); // this will wait 1 sec. call_another_func(); // this will wait 1 sec. 除了这篇文章之外,我想我已经得到了你想要做的事情:在整个脚本中的每一个函数之前或之后运行一个函

如何设置所有函数的勾选功能

function tick_func(){    //for all func,
  sleep(1);
}

//sample function    
call_any_func();              // this will wait 1 sec.
call_another_func();          // this will wait 1 sec.
除了这篇文章之外,我想我已经得到了你想要做的事情:在整个脚本中的每一个函数之前或之后运行一个函数

PHP不提供此功能。您必须在希望影响的任何函数的开头或结尾手动键入此函数调用

<?php
function some_func_sleep() {
    sleep(1);
}

function call_any_func() {
    some_func_sleep();
    // whatever you actually want it to do
}

function call_another_func() {
    some_func_sleep();
    // whatever other thing you want it to do
}

call_any_func();
call_another_func();

根据您提供的信息,我所能想到的可能就是您正在尝试做的事情:

declare(ticks=1);

// using a function as the callback
register_tick_function('all_func_sleep', true);

// your code here...

unregister_tick_function('all_func_sleep');

正如Matchu在下面所说的,这将在每个语句之后调用,而不是在函数调用上调用,但是如果您最小化寄存器之间的代码量。。。取消注册_tick _function()调用,您可以近似此功能。

我想把速度降到1000以上,函数。。。。函数示例_handler(){if function sleep(1);}是否在每次调用其他函数后都尝试执行
all _func_sleep()
?我不熟悉滴答声,也不提供精彩的示例。这到底是做什么的?提供了更多的信息(指向)@problem:interest特性。我认为它不太符合OP的要求,因为它似乎会在每个语句之后运行,而不是在每个函数调用之后运行,但是,考虑到这个不清楚的问题,谁知道呢+1@Matchu:是的,但如果他需要做的工作量有限,并且可以将其放入循环(甚至只是按程序),他可以使用
取消注册(unregister_tick_function()
来划分工作区。我将更新答案以反映这一点。勾号是在声明区域内调用的函数内的语句上运行,还是仅在堆栈的最外层运行?