When a node becomes unavailable, the script switches the domain to the next IP in the pool on its own and reports it in Telegram. Traffic keeps flowing, and you do not have to edit DNS manually.

The script has been tested and debugged and is suitable for production use. Provided as is.

Why You Need It#

The scenario is familiar to everyone who works with traffic:

  • A site or landing page suddenly stops responding
  • The reason — the node is blocked or unavailable
  • Traffic is lost until you manually change the A record in Cloudflare

Now this happens automatically.

How the Automation Works#

We have prepared a PHP script that can be run via cron or as a daemon. It does the following:

  • Checks node availability via a specified URL (GET or POST with JSON payload).
  • If there is no valid response (200, 301, 302) within 5 seconds — the node is considered unavailable.
  • Queries the list of A records in Cloudflare via API.
  • Finds the current IP and replaces it with the next one in rotation from the specified pool:
Pool: [1.1.1.1, 2.2.2.2, 3.3.3.3]
Was IP: 2.2.2.2 → becomes: 3.3.3.3
Was last → becomes first
  • Updates the DNS record via the Cloudflare API.
  • Sends a notification to Telegram so you stay informed.

What You Get#

  • Minimal downtime — the IP changes within seconds of a failure.
  • Easy scaling — add as many nodes to the pool as you want.
  • Full autonomy — no manual DNS edits.
  • Telegram notifications — you learn about every action in real time.

How to Set Up#

  • Install PHP >= 7.4.
  • Specify in the config:
    • domain
    • hostname (e.g., node1.domain.com)
    • Cloudflare API Token and Zone ID
    • IP address pool
    • Telegram bot token
    • chat ID (see below)
  • Add the script call to cron or run it as a systemd service.

How to Get a Telegram Chat ID#

There are two simple methods:

Method 1 — via @userinfobot#
  • Open Telegram.
  • Find the bot @userinfobot.
  • Start it — it will immediately show your ID. This is the chat_id you need.
Method 2 — via your own bot#

If you want to receive notifications from your own bot:

  • Send any message to your bot.
  • Go to the following link, substituting your token:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates

Find this line in the JSON response:

"chat": {
  "id": 123456789,
  ...
}

123456789 is your chat_id.

How to Run the Script#

Choose a convenient method:

1. Via cron#

Run the script regularly, for example, every 2 minutes:

*/2 * * * * php /path/to/checker.php

Replace /path/to/checker.php with the actual path to your file.

2. Via web (over HTTP)#

Place the script on a server accessible via URL, for example:

https://yourhost.com/tools/checker.php

You can call it:

  • from monitoring systems (UptimeRobot, Pingdom, HetrixTools)
  • from CI/CD pipelines (GitLab CI, Jenkins)
  • from automation systems (Home Assistant, Zabbix)
  • manually via browser or curl:
curl https://yourhost.com/tools/checker.php

Download the script