Home > Back-end >  How best listen to incoming webhooks in PHP?
How best listen to incoming webhooks in PHP?

Time:04-15

So I have a PHP script that listens for incoming webhooks. But: where do I put it, so that it permanently runs in the background and listens for those webhooks? I have done some PHP coding before, but never websites.

I admit this is a nooby question, but I seriously don't know and would appreciate any help.

CodePudding user response:

A "webhook" is just a fancy term for some code which makes a HTTP request to a particular URL (usually in response to itself receiving an incoming HTTP request from somewhere, or at the time when some other internal event occurs within the application where the webhook is defined). Basically it's a conceptual technique which allows a degree of asynchronous communication between web applications in a controlled way.

So a PHP program which listens for webhook requests is really no different to any other PHP program which is accessible via a webserver - both are simply executed in a response to a HTTP request being received by the webserver. Whether that request comes from a browser, a "webhook" script, or any other kind of computer program is largely irrelevant.

Your webserver is already running in the background and doing the listening. Therefore you can just deploy your script in the normal way, to somewhere your webserver can make use of it to respond to requests to the URL you've provided to the webhook.

CodePudding user response:

Generally the endpoints for webhooks are just regular PHP pages. The script doesn't need to be running and "listen" for webhook calls - the webhook call will send a request to a particular URL. The webserver will then execute the PHP script at that URL.

The location of the file depends on your webserver. On Debian with Apache, the default web root is /var/www/htdocs/. So if your site is www.jerm.com, putting your file at /var/www/htdocs/webhook.php would result in a URL of www.jerm.com/webhook.php

  • Related