Think of the difference between phoning a shop every hour to ask whether your order has arrived, and the shop texting you when it does. The second approach is a webhook: it uses fewer resources and reacts faster. Payment gateways, GitHub, Telegram and automation tools such as n8n all use them.
How it works
- You register a URL on your site with the service, such as
https://example.com/hooks/payment, and pick the events you care about. - When an event happens, the service sends a
POSTrequest with the details as JSON. - Your code checks that the request really came from the service, using a signature or shared secret.
- Your code replies quickly with
200, then does any heavy work afterwards. - If the reply fails, the service retries according to its policy.
Example: receiving a GitHub webhook in PHP
<?php
$payload = file_get_contents('php://input');
$secret = getenv('WEBHOOK_SECRET');
$expected = 'sha256=' . hash_hmac('sha256', $payload, $secret);
$received = $_SERVER['HTTP_X_HUB_SIGNATURE_256'] ?? '';
if (!hash_equals($expected, $received)) {
http_response_code(401);
exit('Invalid signature');
}
$event = json_decode($payload, true);
// log the event or queue it for processing
http_response_code(200);
hash_equals compares the two signatures safely. Payment gateways use different header names, but the idea is the same.
Common problems
- A 403 before the request reaches your code: a web application firewall may be blocking it: see ModSecurity 403.
- Redirects: if your site redirects
httptohttpsor addswww, the service may not follow it and the POST data is lost. Register the final URL directly. - Slow replies: long processing before responding causes timeouts and retries.
- Telegram bots: you can’t use a webhook and getUpdates at the same time: that’s what causes 409 Conflict.
On ArabyHost
Any PHP script on our hosting plans can receive webhooks, over HTTPS thanks to the free SSL certificates issued automatically. On AI/Developer plans the receiver can also be a Node.js or Python app. Imunify360 protects the server, so if a legitimate webhook is blocked, ask the Araby AI assistant in the panel to read the error log, or contact support. Using n8n? See n8n webhook not working.
FAQ
What's the difference between a webhook and an API?
With an API your app pulls data itself; with a webhook the service pushes data to you when the event happens. Many services offer both.
Why do I receive the same webhook more than once?
Services retry when they don't get a successful 2xx response in time. Make your handler skip duplicates using the event's ID.
Do webhooks work on a site without HTTPS?
Many services refuse or warn about unencrypted URLs, and the data travels in the clear anyway. Always use an HTTPS URL with a valid certificate.