Download the PHP package fperdomo/php-agi without Composer
On this page you can find all versions of the php package fperdomo/php-agi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-agi
PHPAGI
PHPAGI is a PHP library that simplifies building Asterisk AGI (Asterisk Gateway Interface), AMI (Asterisk Manager Interface), and FastAGI applications. This repository is a modernized fork of the original welltime/phpagi project and is updated to be compatible with PHP 8.3+ while maintaining a familiar API for easier migration.
Table of Contents
- Features
- Requirements
- Installation
- Usage
- AGI script
- FastAGI
- Asterisk Manager (AMI)
- Examples
- Directory layout
- Contributing
- License
Features
- AGI class for interactive call control
- FastAGI server support
- Asterisk Manager Interface (AMI) integration
- Updated for PHP 8.3+ compatibility
- Maintains the original API design to simplify migration
- Extensions: ext-sockets
Requirements
- PHP 8.3 or higher
- Asterisk PBX (with AGI / FastAGI support)
- Composer for dependency management
Why this fork?
The original welltime/phpagi project is now archived, and many deployments still rely on the classic API.
This package modernizes PHPAGI for PHP 8.3+ while keeping a familiar developer experience to simplify migration.
Installation
Install the package via Composer (replace with your vendor if you publish under a different name):
Usage
Below are minimal examples to get started with AGI, FastAGI, and AMI usage.
AGI script
AGI scripts are executed by Asterisk from the dialplan. Place executable PHP scripts in the location Asterisk can call.
Example: simple AGI script
Make the script executable:
In extensions.conf:
More AGI Examples
See the examples/agi/ directory for more comprehensive examples:
- interactive-menu.php - Interactive IVR menu with DTMF input
- call-recording.php - Recording caller messages and storing metadata
- database-lookup.php - Using Asterisk database for caller lookups
- call-center-router.php - Complete call center routing with VIP detection, multi-level menus, and statistics
- verbose.php - Simple verbose logging example
Production quickstart (AGI)
1) Install:
2) Put scripts in Asterisk AGI directory (commonly /var/lib/asterisk/agi-bin/). 3) Make executable and ensure correct owner:
4) In your dialplan:
5) Debug:
- Check Asterisk console: asterisk -rvvvvv
- Log in script using error_log() (stderr) and/or a file logger.
FastAGI as a systemd service
Running FastAGI with systemd (recommended)
Create /etc/systemd/system/phpagi-fastagi.service:
Enable & start:
Dialplan:
AMI security notes
- Never expose AMI (5038) publicly.
- Use a dedicated AMI user with minimum permissions.
- Prefer binding to localhost or a private network interface.
- Store credentials in environment variables (or secrets manager).
FastAGI
FastAGI runs as a server process and handles AGI commands over TCP. Run a FastAGI server and configure Asterisk to call it.
Example FastAGI dispatcher:
Configure Asterisk to use FastAGI in extensions.conf:
FastAGI Example
See examples/fastagi/server.php for a complete FastAGI server implementation with example handlers.
Asterisk Manager (AMI)
Use the AgiAsteriskManager class to connect to Asterisk's management interface to receive events or take actions programmatically.
Example:
Environment Variables:
For security, use environment variables for sensitive configuration:
More AMI Examples
See the examples/ami/ directory for more comprehensive examples:
- ping.php - Simple AMI connection and ping test
- originate-call.php - Originating outbound calls programmatically
- monitor-events.php - Real-time event monitoring with event handlers
Examples
The examples/ directory contains practical, ready-to-use examples demonstrating various PHPAGI features:
AGI Examples (examples/agi/)
| Example | Description |
|---|---|
| interactive-menu.php | Interactive IVR menu system with DTMF input handling |
| call-recording.php | Record caller messages and store metadata in Asterisk database |
| database-lookup.php | Lookup caller information using Asterisk database (AstDB) |
| call-center-router.php | Complete call center with VIP detection, queues, and statistics |
| verbose.php | Simple verbose logging demonstration |
| hello.php | Minimal low-level AGI implementation without using PHPAGI class |
AMI Examples (examples/ami/)
| Example | Description |
|---|---|
| ping.php | Simple AMI connection test using Ping action |
| originate-call.php | Originate outbound calls programmatically with custom variables |
| monitor-events.php | Real-time event monitoring with custom event handlers |
FastAGI Examples (examples/fastagi/)
| Example | Description |
|---|---|
| server.php | Complete FastAGI server implementation |
| handlers/your-script.php | Example FastAGI handler script |
Running the Examples
AGI Examples:
AMI Examples:
FastAGI Examples:
Directory layout
A suggested layout for this project:
Contributing
Contributions are welcome. Suggested workflow:
- Fork the repository
- Create a feature branch:
git checkout -b feature/fooBar - Commit your changes
- Push to your fork
- Open a Pull Request
Testing & CI: Ensure compatibility with PHP 8.3+; GitHub Actions or similar CI is recommended.
License
This project is released under the GNU Lesser General Public License (LGPL-2.1+), consistent with the original PHPAGI license.
All versions of php-agi with dependencies
ext-sockets Version *