Automated Billing (Autobill)
CDR Processing & Automated Billing Configuration
The Autobill system processes call detail records (CDRs) and generates automated billing for VoIP services. This automated process ensures accurate and timely billing for all VoIP usage.
Overview
Autobill is a critical component that processes CDRs from your PBX servers and generates billing records in WHMCS. The system runs as a scheduled CRON job and integrates seamlessly with WHMCS billing cycles.
Key Features:
Automated CDR processing
Real-time billing generation
Multi-server support
Flexible scheduling
Debug and testing capabilities
Special Number Billing support
In ictVoIP Billing v1.4.0, Autobill remains the engine that turns rated CDRs into billable usage. FusionPBX now offers three billing script options:
- Autobill v2 (
autobill_v2.php) The enhanced browser-based UI with real-time statistics, progress indicators, and color-coded debug output. Creates separate invoices for each FusionPBX service per client. Recommended for clients who prefer itemized billing.
- Autobill v3 (
autobill_v3.php) - New in v1.4.0 Consolidated billing script that combines multiple FusionPBX services per client into a single invoice. Supports International, National, and Special Rate call types. Provides dynamic admin email notifications that scale to any number of services. Recommended for clients who want simplified billing with one invoice per billing period for all VoIP services.
- Autobill v1 (
autobill.php) The original headless script for CRON execution. Still supported for legacy deployments.
Choosing Between v2 and v3:
Use v2 if clients need separate invoices for each service (e.g., different cost centers)
Use v3 if clients want consolidated billing (all VoIP services on one invoice)
Both support the same call types and billing features
Both use identical underlying billing logic
Other supported server modules (for example, Vodia or custom
integrations) continue to ship with their own autobill.php-style
scripts, which are typically used only for headless CRON execution.
CRON Configuration
Scheduling Requirements:
The Autobill script must run before your WHMCS daily CRON job to ensure proper billing processing.
Important
AlmaLinux 9 / systemd Timezone Configuration
On AlmaLinux 9 / systemd-based systems, cron jobs may default to UTC even when:
Server time is correct
PHP-FPM timezone is correct
WHMCS timezone is correctly configured
WHMCS automation relies on the execution time of cron.php, not just internal settings.
Solutions:
Per-CRON Timezone (Recommended): Specify
TZ=explicitly in each WHMCS cron job to avoid automation running early or late after server migrations.System-Wide PHP INI: Update the system PHP INI configuration to set
date.timezonesystem-wide if this option is available on your hosting environment.
Recommended Schedule:
WHMCS Daily CRON: 1:00 AM
Autobill CRON: 12:55 AM (5 minutes before)
Alternative Schedule:
WHMCS Daily CRON: 2:00 AM
Autobill CRON: 12:45 AM (75 minutes before)
CRON Entry Format:
Replace MYMODULE with your installed server module and America/Toronto with your timezone:
# FusionPBX - Autobill v2 (separate invoices per service)
55 00 * * * TZ=America/Toronto GET https://www.mywhmcsserver.com/modules/servers/fusionpbx/autobill_v2.php?runfrom=cron
# FusionPBX - Autobill v3 (consolidated invoices - NEW in v1.4.0)
55 00 * * * TZ=America/Toronto GET https://www.mywhmcsserver.com/modules/servers/fusionpbx/autobill_v3.php?runfrom=cron
# Alternative format with more time
45 00 * * * TZ=America/Toronto GET https://www.mywhmcsserver.com/modules/servers/fusionpbx/autobill_v3.php?runfrom=cron
# PHP CLI format (alternative)
55 00 * * * TZ=America/Toronto /usr/bin/php -q /home/USERNAME/public_html/whmcs/modules/servers/fusionpbx/autobill_v3.php runfrom=cron
CRON Parameters:
TZ=America/Toronto - Explicit timezone (required for AlmaLinux 9 / systemd)
55 00 - Time (12:55 AM in specified timezone)
* * * - Daily execution
GET - HTTP method (or /usr/bin/php -q for CLI)
runfrom=cron - Execution parameter
FusionPBX Script Selection:
autobill_v2.php - Separate invoices for each service (itemized billing)
autobill_v3.php - Consolidated invoices (all services combined per client)
Other Server Module Examples:
Vodia:
vodia/autobill.phpCustom:
custom/autobill.php
Note
For FusionPBX deployments, choose between v2 (separate invoices) or v3 (consolidated invoices) based on your billing requirements. Both scripts use the same underlying billing logic and support all call types (International, National, Special Rates). See the CRON reference documentation at https://ictvoip.ca/docs/cron-reference.html for detailed setup instructions.
Manual Testing
Browser Testing:
Test your Autobill installation by accessing the script directly in your browser:
# FusionPBX (Autobill v2 - separate invoices)
URL: https://www.mywhmcsserver.com/modules/servers/fusionpbx/autobill_v2.php?runfrom=cron
Method: GET
Authentication: Required
# FusionPBX (Autobill v3 - consolidated invoices)
URL: https://www.mywhmcsserver.com/modules/servers/fusionpbx/autobill_v3.php?runfrom=cron
Method: GET
Authentication: Required
# Other modules (generic example)
URL: https://www.mywhmcsserver.com/modules/servers/MYMODULE/autobill.php?runfrom=cron
Method: GET
Authentication: Required
Test Configuration:
Before testing, ensure proper configuration:
Set Test Date - Configure client’s next due date to current date
Enable Debug - Activate debug mode for detailed output
Check Permissions - Verify script access permissions
Review Logs - Monitor execution logs
Test Process:
Access Script - Open autobill URL in browser
Monitor Output - Watch for processing results
Review Results - Check billing calculations
Verify Billing - Confirm invoice generation
Debug Configuration
Enable Debug Mode:
Activate debug mode to view detailed processing information:
Navigate to ictVoIP Billing → Billing Management
Enable CDR Autobill Debug
Run manual autobill execution
Review debug output
Debug Information:
Debug mode provides detailed information including: * CDR processing status * Rate calculations * Billing summaries * Error messages * Processing timestamps
Debug Output Example:
[DEBUG] Starting Autobill Process
[DEBUG] Processing Server: FusionPBX-01
[DEBUG] Found 150 CDR records
[DEBUG] Applied rates to 145 records
[DEBUG] Generated billing for 5 clients
[DEBUG] Process completed successfully
Billing Integration
WHMCS Integration:
Autobill integrates with WHMCS billing cycles:
Invoice Generation - Creates invoices for processed CDRs
Billing Date Management - Updates next due dates
Product Billing - Processes monthly/annual billing
Invoice Delivery - Sends invoices to clients
Billing Cycle Process:
Autobill Execution - Process CDRs and calculate charges
WHMCS Daily CRON - Generate invoices and update billing dates
Invoice Delivery - Send invoices to clients
Payment Processing - Handle payment collection
Important Notes:
Autobill does not increment product next billing dates
WHMCS daily CRON handles billing date updates
Monthly invoices are generated after Autobill processing
Billing dates are updated during WHMCS daily CRON execution
Performance Optimization
New in version 1.4.0-Beta.11: Tariff lookup performance optimization (159x faster)
Processing Time Considerations:
Small Installations - 5 minutes before WHMCS CRON
Medium Installations - 15 minutes before WHMCS CRON
Large Installations - 30+ minutes before WHMCS CRON
Factors Affecting Processing Time:
Number of Servers - More servers = longer processing
CDR Volume - Higher call volume = longer processing
Server Performance - CPU and memory limitations
Network Latency - API response times
Tariff Table Size - Larger tariff tables require more lookups
Tariff Lookup Optimization (v1.4.0-Beta.11+):
The FusionPBX module includes an optimized tariff lookup system that dramatically improves processing speed for large CDR volumes:
In-Memory Cache - Tariff tables under 500,000 entries are loaded into memory once
Zero DB Queries Per CDR - After initial cache load, lookups are pure in-memory operations
Automatic Strategy Selection - System chooses optimal approach based on table size
Verified Results - Billing amounts remain identical to previous versions
Performance Benchmarks:
Metric |
Before (v1.4.0-Beta.10) |
After (v1.4.0-Beta.11) |
|---|---|---|
Processing Time (2,400 CDRs) |
636 seconds (~10.6 min) |
4 seconds |
DB Queries per CDR |
Up to 10 (recursive) |
0 (cached lookup) |
Memory Usage |
Low |
~50MB for 322K tariff entries |
PHP Memory Requirements:
For optimal tariff cache performance, ensure your PHP configuration meets these requirements:
; Recommended PHP settings for large tariff tables
memory_limit = 8096M
max_execution_time = 300
Optimization Tips:
Monitor Processing Time - Track execution duration
Adjust Scheduling - Increase time buffer if needed
Server Optimization - Improve server performance
CDR Cleanup - Regular CDR database maintenance
Memory Allocation - Ensure sufficient PHP memory for tariff caching
Special Number Billing
Autobill supports Special Number Billing for products configured with custom rate rules. When enabled, special rate patterns are processed before standard tariff billing.
How It Works:
CDRs are checked against special rate patterns first
Matching CDRs are billed using the configured special rate rules
Non-matching CDRs are skipped (not billed) when special rates are enabled
Special rate calls are grouped by pattern on invoices
Invoice Display:
Special Rate Calls (29/12/2025 to 29/01/2026)
[OUTBOUND] 1300* (flat_per_call): 4 calls, 11 min, $1.40
[OUTBOUND] 1800* (flat_per_call): 1 calls, 5.7 min, $0.35
For detailed configuration, see FusionPBX Configuration Guide under “Special Number Billing”.
Error Handling
Common Errors:
Connection Timeout - Server unavailable
Authentication Failed - Invalid credentials
Permission Denied - File access issues
Database Errors - CDR processing issues
Error Resolution:
Check Server Status - Verify PBX server availability
Review Credentials - Confirm API authentication
Check Permissions - Verify file and database access
Monitor Logs - Review error logs for details
Log Monitoring:
Monitor autobill logs for issues:
# Check autobill logs
tail -f /var/log/autobill.log
# Check WHMCS logs
tail -f /var/log/whmcs.log
# Check system logs
tail -f /var/log/syslog
Security Considerations
Access Control:
HTTPS Required - Always use secure connections
Authentication - Implement proper access controls
IP Restrictions - Limit access to trusted IPs
Log Monitoring - Monitor access attempts
Best Practices:
Secure Credentials - Use strong API passwords
Regular Updates - Keep scripts updated
Backup Configuration - Maintain backup copies
Audit Logs - Review access logs regularly
Troubleshooting
Common Issues:
Script Not Executing - Check CRON configuration
No CDRs Processed - Verify server connectivity
Billing Errors - Check rate configuration
Performance Issues - Monitor processing time
Debug Steps:
Check CRON Status - Verify CRON job execution
Test Manual Execution - Run script manually
Review Error Logs - Check for error messages
Verify Configuration - Confirm settings
Support Information:
For autobill issues, provide: * CRON configuration * Error messages and logs * Server module details * Processing time information
Next Steps
After configuring autobill:
Test Execution - Run manual tests
Monitor Performance - Track processing times
Review Billing - Verify invoice generation
Production Deployment - Enable automated execution