Skip to content

Instantly share code, notes, and snippets.

@ideadude
Created May 7, 2025 12:05
Show Gist options
  • Save ideadude/8d5c4af7c3bad4de391e458d91e54b05 to your computer and use it in GitHub Desktop.
Save ideadude/8d5c4af7c3bad4de391e458d91e54b05 to your computer and use it in GitHub Desktop.
Dummy webhook handler for testing. Saves incoming data to a file.
<?php
/**
* Just place this file on the webserver and then point your webhook to the location.
* This will save the incoming timestamp and data to a webhook-handler.log file in the same folder.
* Use `tail -f webhook-handler.log` to monitor the log file.
*/
// Set the log file path
$logFile = __DIR__ . '/webhook-handler.log';
$timestamp = date('Y-m-d H:i:s');
// Read raw POST body
$rawInput = file_get_contents('php://input');
// Try to decode JSON if it exists
$jsonData = json_decode($rawInput, true);
// Prepare formatted data for logging
$requestData = [
'timestamp' => $timestamp,
'raw_input' => $rawInput,
'json_decoded' => $jsonData,
'_REQUEST' => $_REQUEST,
];
// Convert to readable format
$logEntry = "[" . $timestamp . "] Incoming Request:\n" . print_r($requestData, true) . "\n----------------------\n";
// Write to the log
file_put_contents($logFile, $logEntry, FILE_APPEND | LOCK_EX);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment