Skip to content

Instantly share code, notes, and snippets.

@xtetsuji
Created November 8, 2024 15:10
Show Gist options
  • Save xtetsuji/7ea8a27b7eb0d21f3b01d8023149b8e1 to your computer and use it in GitHub Desktop.
Save xtetsuji/7ea8a27b7eb0d21f3b01d8023149b8e1 to your computer and use it in GitHub Desktop.
PHP version xtrace
@xtetsuji ➜ /workspaces/codespaces-blank $ php tick_test.php
Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port).
Executing /workspaces/codespaces-blank/tick_test.php on line 9
Hello
Executing /workspaces/codespaces-blank/tick_test.php on line 12
Executing /workspaces/codespaces-blank/tick_test.php on line 13
Executing /workspaces/codespaces-blank/tick_test.php on line 14
Result: 10
Executing /workspaces/codespaces-blank/tick_test.php on line 15
<?php
declare(ticks=1);
function trace_execution() {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
echo "Executing {$backtrace['file']} on line {$backtrace['line']}\n";
}
register_tick_function('trace_execution');
// サンプルコード
echo "Hello\n";
$a = 5;
$b = $a * 2;
echo "Result: $b\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment