PHP 使用声明 ?什么是蜱虫?

发布于 2024-08-24 21:22:19 字数 273 浏览 4 评论 0原文

我对 PHP 函数 declare 有点困惑。

到底什么是单蜱?我认为一个勾号等于一行代码?

但如果我使用:

function myfunc() {
        print "Tick";   
}

register_tick_function("myfunc");

declare(ticks=1) {
   echo 'foo!bar';
}

脚本打印:

“Tick”2 次?

I am a little bit confused by the PHP function declare.

What exactly is a single tick? I thought a tick equals one line of code?

But if I use:

function myfunc() {
        print "Tick";   
}

register_tick_function("myfunc");

declare(ticks=1) {
   echo 'foo!bar';
}

The script prints:

"Tick" 2 Times??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

街角迷惘 2024-08-31 21:22:19

每行都会有一个勾号;以及每个块 {}
尝试一下:

declare(ticks=1) echo 'foo!bar';

没有阻塞,没有额外的勾选。

declare(ticks=1) {{ echo 'foo!bar'; }}

更多无关的块=更多的蜱虫。

PS:顺便说一下,刻度线是一种非常奇特的功能,它们只在少数极其罕见的情况下才有用。它们不等同于线程或任何东西。如果对您来说,蜱虫是问题的解决方案,那么您应该在另一个问题中发布您的问题,因为它可能不是正确的解决方案。

You get a tick for each line ; and each block {}
Try that:

declare(ticks=1) echo 'foo!bar';

No block, no extra tick.

declare(ticks=1) {{ echo 'foo!bar'; }}

More extraneous blocks = more ticks.

PS: by the way, ticks are quite the exotic feature and they're only useful in a few extremely rare situations. They are not equivalent to threading or anything. If, for you, ticks are the solution to a problem then you should post about your problem in another question because it's probably not the right solution to it.

糖粟与秋泊 2024-08-31 21:22:19

关于蜱虫是什么,您是在正确的轨道上。

https://web.archive.org/web/20100801093511/http://www.tuxradar.com/practicalphp/4/21/0" archive.org/web/20100801093511/http://www.tuxradar.com/practicalphp/4/21/0

简单来说,蜱虫是一个特殊事件
PHP 内部发生的每个
执行了一定数量的时间
的声明。这些陈述是
PHP 内部且松散对应
到脚本中的语句。你
可以控制多少条语句
需要使用以下命令来触发一个刻度
声明()函数,你可以
注册函数来执行时
勾选发生通过使用
register_tick_function() 函数。作为
已经提到过,语法为
声明非常不寻常,所以要做好准备
震惊!

You are on the right track as to what a tick is.

https://web.archive.org/web/20100801093511/http://www.tuxradar.com/practicalphp/4/21/0

Put simply, a tick is a special event
that occurs internally in PHP each
time it has executed a certain number
of statements. These statements are
internal to PHP and loosely correspond
to the statements in your script. You
can control how many statements it
takes to set off a tick using the
declare() function, and you can
register functions to execute when a
tick occurs by using the
register_tick_function() function. As
mentioned already, the syntax for
declare is very unusual, so be ready
for a shock!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文