Bot Operations: Cron, Testing, Performance and Releases
Three different cron execution modes
| Mode | Who initializes the runtime? | Helper availability |
|---|---|---|
| Botlify scheduled child task | Platform child runner | Call tg_all_fun() in the target script |
| Platform master cron | Platform bootstrap | Platform initializes its own helpers |
Direct php my-script.php |
Your script/environment | No automatic Botlify initialization |
The scheduler currently prefers an isolated PHP subprocess where available, with an isolated HTTP runner fallback. The scheduling code enforces a 25-second execution/request budget on these paths. PHP/server configuration can impose additional limits. A long job should store a checkpoint and process a bounded batch on the next scheduled run, not loop forever.
Scheduling a bot task does not require Telegram helpers. Helpers are required only if that task calls native tg_* functions. Use your bot's target filename in the Cron interface; do not overwrite the platform's root cron.php.
Normal PHP task
<?php
declare(strict_types=1);
// No Telegram helper use, so no loader call.
file_put_contents(__DIR__ . '/last-run.txt', gmdate('c'), LOCK_EX);
Hosted task sending a notification
<?php
declare(strict_types=1);
tg_all_fun();
$adminId = (string)(getenv('ADMIN_CHAT_ID') ?: '');
if ($adminId === '') {
error_log('Cron configuration: ADMIN_CHAT_ID is missing.');
return;
}
$result = tg_send($adminId, 'Scheduled task completed.');
if (!($result['ok'] ?? false)) {
error_log('Cron notification failed; inspect the API result securely.');
}
Test in increasing scope
- Check PHP syntax and the sandbox audit.
- Confirm the hosted bot's real PHP version and helper loader.
- Test identity and a single private-chat message.
- Test edit/delete only on messages created by the test.
- Test callbacks with a freshly pressed button, then media with files owned by that same bot.
- Use a dedicated channel/group for permission-dependent operations.
- Configure business/payment/widget/inline fixtures only when those capabilities are actually available.
A function-existence test is not a live API test. An API success is not proof of the intended visual rendering on every Telegram client. NOT_TESTED must remain distinct from FAIL and PASS. Tests that spend Stars, modify a webhook, ban users or delete resources require deliberately selected test data.
Diagnose the right layer
| Symptom | Layer | Action |
|---|---|---|
Undefined tg_allfun() |
Bot code | Correct spelling: tg_all_fun() |
Undefined tg_all_fun() |
Deployment/entrypoint | Verify runtime deployment and hosted execution |
Undefined tg_send() |
Initialization | Call loader before the first helper, including cron code |
| Integer chat ID rejected | Older helper version | Deploy current `int |
| Missing telegram_api_helpers.php | Old runtime release | Current runtime has no dependency on that file |
| MySQL 1045 | Platform DB credentials/access | Verify the configured account with the host; do not publish passwords |
| snmp.so missing dependency | PHP installation | Hosting must repair its extension/library configuration |
| HTTP/API Bad Gateway | Gateway/upstream | Inspect timing and service connectivity; retry only where safe |
| 429 / retry_after | Rate limiting | Schedule after the indicated delay; avoid rapid loops |
| cURL timeout | Transport | The remote result may be unknown; do not blindly replay paid or destructive calls |
| Bot does not see group text | Telegram configuration | Check privacy mode, event type and permissions |
| Permission denied on local file | Storage/runtime | Check the bot's own folder and allowed path |
A custom bot try/catch block controls its own logging. Native missing-function errors are not automatically rewritten into a special loader error message. Never post bot tokens, database passwords or token-bearing file URLs into logs/reports.
Retry policy and execution time
The shared transport currently contains a network retry path and a plain-text fallback for certain formatting failures. A helper request can therefore take longer than one network round trip. Convenience helpers such as automatic edit/media fallback may also perform more than one request. Do not assume one helper invocation always means exactly one outbound call.
For transactional operations, account for ambiguous outcomes and consult the official response semantics. Queue a retry for later rather than sleeping through the entire webhook/cron execution budget. Prefer the exact generated API wrapper when you need precise parameter control, and inspect its returned ok, description, error_code and optional parameters fields.
Performance without unsupported promises
OPcache reduces repeated compilation work. It does not make Telegram respond faster. tg_all_fun() controls function registration and does not issue a Telegram request itself. The helper source still exists in the PHP file; opt-in loading is not a guarantee of zero parsing cost.
Measure actual webhook handling, database work and Telegram request durations separately. Compare the same operation, PHP version and warm-cache conditions before deciding that helper use causes a slowdown. Report median and tail latency across several requests rather than treating a single request as a benchmark. Never compare a multi-test report's total duration with one-message latency.
The PHP version selected in a hosting panel can differ from the webhook or cron interpreter. Compare runtime reports. Browser upload limits, Telegram upload limits and getFile download limits are separate settings.
Deployment and rollback
Back up the current release and your bot data separately. Add the transition loader guard to existing helper-based bot and cron entrypoints before deploying opt-in runtime files. Deploy matching telegram.php, bootstrap.php, webhook.php and cron.php together. Update isolated runner code when included in your release. Test on a dedicated bot before restoring normal traffic.
Preserve .env and database.db during code replacement. Do not copy production credentials into example files. If a release fails, restore the matching previous code set; do not silently restore an old database over new user activity. OPcache timestamp validation affects how quickly edited code becomes visible.
See the deployment checklist, runtime guide and complete helper reference.