PHP Heartbeat - Code Examples
Integrate MoniTao into your PHP scripts in just a few lines of code.
PHP remains the most used language for server scripts and scheduled tasks. Whether you use a framework (Laravel, Symfony) or vanilla PHP, MoniTao heartbeat integration is simple.
Here are several methods to send a heartbeat ping from PHP, from simplest to most robust.
Simple method: file_get_contents
The quickest method, perfect for simple scripts:
Robust method: cURL
More control over timeouts and errors:
Framework: Guzzle HTTP
If you're already using Guzzle in your project:
post('https://monitao.com/api/heartbeat/ping/YOUR_TOKEN', [\n 'timeout' => 10\n]);
FAQ - PHP Heartbeat
Can the ping slow down my script?
The ping takes a few milliseconds. If your script is time-critical, run the ping asynchronously or with a short timeout (2-3 sec). If the ping fails, your script continues.
Should I check the ping response?
Not required. If MoniTao doesn't receive the ping, it will alert. But checking the response lets you log ping errors on the application side.
How do I handle the case where MoniTao is down?
Use a short timeout (5-10 sec) and a try/catch. If the ping fails, log the error but let your script continue. MoniTao has 99.9%+ SLA.
Can I include data with the ping (duration, status)?
Yes! MoniTao accepts optional POST parameters like duration (in seconds) and status. Check the API documentation for details.
Ready to Sleep Soundly?
Start free, no credit card required.