Tailing webhooks with PHP

submited by
Style Pass
2022-06-22 06:30:04

If you run an application that produces a lot of webhooks like EmailEngine, you might want to observe what kind of data is even sent before you try to start consuming it. This post shows an easy way to do this with PHP.

The concept is simple. Your webhooks producer posts all webhooks to a PHP script. That script then appends all incoming JSON requests with some metadata to a log file. You would tail that log file and pipe it to the jq command, resulting in a real-time pretty printed log output. As the content is stored in a log file, you can stop tailing any time you want and return to it later.

First, if you do not have jq yet installed, you can add it using your package manager. For example, in Ubuntu, you can run the following:

Next, create a log file. I'll be running PHP scripts under the www-data user, so I need to make sure PHP can write to that file.

Next, get the example PHP script from here and, if needed, change the log file path at the beginning of the script. Store this script somewhere in your web server so that you would be able to run requests against it.

Leave a Comment