You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows版Snaketail外部工具参数配置及触发PHP脚本求助

Hey there, I’ve worked with Snaketail on Windows before, so let’s walk through how to set up keyword-based triggers for your PHP script—since the official docs and GitHub repo don’t cover this, here’s a step-by-step guide that should get you sorted:

How to Trigger a PHP Script on Highlighted Log Lines in Windows Snaketail

Step 1: Create a Highlighting Rule with External Command Trigger

  1. Open Snaketail, load your target log file, and head to View > Highlighting Rules (or hit Ctrl+H to open the rules panel).
  2. Click Add to make a new rule:
    • In the Text to find box, type the keyword (or regex pattern) you want to use to trigger the script. Check the Regular expression box if you’re using regex for more complex matches.
    • Set a highlight style (color, bold, italic) so you can visually confirm when the rule matches—this is optional but helpful for testing.
    • Scroll down to the External command section at the bottom of the rule editor. Check the box that says Execute command when line matches.

Step 2: Configure the Command to Pass the Log Line to Your PHP Script

This is where you’ll link Snaketail to your PHP script and pass the matched log line.

In the Command line field, enter this (adjust paths to match your setup):

php.exe "C:\full\path\to\your\processing-script.php" "%LINE%"
  • php.exe: Use the full path to your PHP executable if it’s not in your system PATH (e.g., C:\Program Files\PHP\8.2\php.exe).
  • "C:\full\path\to\your\processing-script.php": Wrap your script’s full path in quotes to handle spaces in folder/filenames.
  • "%LINE%": This is Snaketail’s built-in variable that inserts the entire matched log line as an argument to your script.

Access the Log Line in Your PHP Script

In your PHP script, you can grab the passed log line using the $argv array (PHP’s way of accessing command-line arguments):

<?php
// Check if we received a log line argument
if (isset($argv[1])) {
    $triggeredLogLine = $argv[1];
    
    // Do your processing here—example: append to a log, send an alert, parse data
    file_put_contents("triggered-events.log", $triggeredLogLine . PHP_EOL, FILE_APPEND);
} else {
    // Handle cases where no line was passed
    error_log("PHP script called without a log line from Snaketail");
}
?>

Step 3: Test and Troubleshoot

  • Save your highlight rule, make sure it’s enabled (check the box next to it in the rules list), then generate a log line that matches your keyword. You should see the line highlight, and your script should run automatically.
  • If the script doesn’t execute:
    • Verify the paths to php.exe and your script are correct—test the command manually in Command Prompt first to rule out path issues.
    • Run Snaketail as Administrator if you hit permission errors (some folders restrict external program execution).
    • Check your script’s output (like the triggered-events.log in the example) to confirm the log line was received properly.

内容的提问来源于stack exchange,提问作者Kim Steinhaug

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:47:31