是否可以在执行PHP脚本的每一行后运行PHP函数?

我的问题与此类似: Is it possible to run code after each line in Ruby?
但是我想用PHP来做.

是否可能,如果可能,怎么样?

你可以 registertick handler

Ticks

A tick is an event that occurs for every N low-level tickable statements executed by the parser within the declare block. The value for N is specified using ticks=N within the declare blocks’s directive section.

Not all statements are tickable. Typically,condition expressions and argument expressions are not tickable.

正如您所看到的,它不完全是“每行代码”,除非您每行只写一个可选择的语句.但它是你能得到的最接近的.

例:

declare(ticks=1);
register_tick_function(function() {
    echo "tick_handler() called\n";
});

echo 'Line 1',PHP_EOL;
echo 'Line 2',PHP_EOL;
echo strtoupper('Line 3'),PHP_EOL;

输出(demo):

tick_handler() called
Line 1
tick_handler() called
Line 2
tick_handler() called
LINE 3
tick_handler() called

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...