Skip to content
Development and deployment2 min read

What is a webhook?

Short answer

A webhook is a mechanism where an outside service sends an HTTP request, usually a JSON POST, to a URL you choose as soon as a specific event happens, such as a successful payment or a new message to a bot. Instead of your app asking the service every minute, the service tells your app when it matters.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. How it works
  2. Example: receiving a GitHub webhook in PHP
  3. Common problems
  4. On ArabyHost

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

  1. You register a URL on your site with the service, such as https://example.com/hooks/payment, and pick the events you care about.
  2. When an event happens, the service sends a POST request with the details as JSON.
  3. Your code checks that the request really came from the service, using a signature or shared secret.
  4. Your code replies quickly with 200, then does any heavy work afterwards.
  5. 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 http to https or adds www, 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.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.