{"id":35425331,"url":"https://github.com/masterfermin02/php-agi","last_synced_at":"2026-01-26T00:13:27.870Z","repository":{"id":331482443,"uuid":"1126302823","full_name":"masterfermin02/php-agi","owner":"masterfermin02","description":"PHPAGI is a PHP library that simplifies building Asterisk AGI","archived":false,"fork":false,"pushed_at":"2026-01-02T16:34:58.000Z","size":64,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-13T19:57:35.105Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/masterfermin02.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-01T16:05:11.000Z","updated_at":"2026-01-02T16:33:25.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/masterfermin02/php-agi","commit_stats":null,"previous_names":["masterfermin02/php-agi"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/masterfermin02/php-agi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterfermin02%2Fphp-agi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterfermin02%2Fphp-agi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterfermin02%2Fphp-agi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterfermin02%2Fphp-agi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/masterfermin02","download_url":"https://codeload.github.com/masterfermin02/php-agi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masterfermin02%2Fphp-agi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28762074,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T23:06:19.311Z","status":"ssl_error","status_checked_at":"2026-01-25T23:03:50.555Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-02T18:14:18.463Z","updated_at":"2026-01-26T00:13:27.863Z","avatar_url":"https://github.com/masterfermin02.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHPAGI\n\nPHPAGI 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.\n\nTable of Contents\n\n- Features\n- Requirements\n- Installation\n- Usage\n  - AGI script\n  - FastAGI\n  - Asterisk Manager (AMI)\n- Directory layout\n- Contributing\n- License\n\n## Features\n\n- AGI class for interactive call control\n- FastAGI server support\n- Asterisk Manager Interface (AMI) integration\n- Updated for PHP 8.3+ compatibility\n- Maintains the original API design to simplify migration\n- Extensions: ext-sockets\n\n## Requirements\n\n- PHP 8.3 or higher\n- Asterisk PBX (with AGI / FastAGI support)\n- Composer for dependency management\n\n## Why this fork?\n\nThe original `welltime/phpagi` project is now archived, and many deployments still rely on the classic API.\nThis package modernizes PHPAGI for PHP 8.3+ while keeping a familiar developer experience to simplify migration.\n\n\n## Installation\n\nInstall the package via Composer (replace with your vendor if you publish under a different name):\n\n```\ncomposer require fperdomo/php-agi\n```\n\n\n## Usage\n\nBelow are minimal examples to get started with AGI, FastAGI, and AMI usage.\n\n### AGI script\n\nAGI scripts are executed by Asterisk from the dialplan. Place executable PHP scripts in the location Asterisk can call.\n\nExample: simple AGI script\n\n```php\n#!/usr/bin/env php\n\u003c?php\n\ndeclare(strict_types=1);\n\nrequire 'vendor/autoload.php';\n\nuse Fperdomo\\PhpAgi\\Agi;\n\ntry {\n    $agi = new Agi();\n    \n    // Answer the call\n    $agi-\u003eanswer();\n    \n    // Speak text using text-to-speech\n    $agi-\u003etext2wav(\"Hello from PHPAGI!\");\n    \n    // Hangup the call\n    $agi-\u003ehangup();\n    \n    exit(0);\n} catch (\\Throwable $e) {\n    // Log errors to stderr for debugging\n    error_log('AGI Error: ' . $e-\u003egetMessage());\n    exit(1);\n}\n```\n\nMake the script executable:\n\n```bash\nchmod +x your-script.php\n```\n\nIn `extensions.conf`:\n\n```ini\nexten =\u003e 123,1,AGI(your-script.php)\nexten =\u003e 123,n,Hangup()\n```\n\n## Production quickstart (AGI)\n\n1) Install:\n```bash\ncomposer require fperdomo/php-agi\n```\n2) Put scripts in Asterisk AGI directory (commonly /var/lib/asterisk/agi-bin/).\n3) Make executable and ensure correct owner:\n\n```bash\nchmod +x /var/lib/asterisk/agi-bin/hello.php\nchown asterisk:asterisk /var/lib/asterisk/agi-bin/hello.php\n```\n4) In your dialplan:\n```bash\n exten =\u003e 123,1,NoOp(Hello AGI)\n same =\u003e n,AGI(hello.php)\n same =\u003e n,Hangup()\n```\n5) Debug:\n\n- Check Asterisk console: asterisk -rvvvvv\n- Log in script using error_log() (stderr) and/or a file logger.\n\n### FastAGI as a systemd service\n\n## Running FastAGI with systemd (recommended)\n\nCreate `/etc/systemd/system/phpagi-fastagi.service`:\n\n```ini\n[Unit]\nDescription=PHPAGI FastAGI Dispatcher\nAfter=network.target\n\n[Service]\nType=simple\nUser=asterisk\nGroup=asterisk\nWorkingDirectory=/opt/phpagi\nExecStart=/usr/bin/php /opt/phpagi/fastagi-server.php\nRestart=always\nRestartSec=2\nEnvironment=APP_ENV=production\n\n[Install]\nWantedBy=multi-user.target\n```\n\nEnable \u0026 start:\n```bash\nsystemctl daemon-reload\nsystemctl enable phpagi-fastagi\nsystemctl start phpagi-fastagi\njournalctl -u phpagi-fastagi -f\n```\n\nDialplan:\n\n```ini\nexten =\u003e 123,1,FastAGI(agi://127.0.0.1:4573/your-script)\n\n```\n\n## AMI security notes\n\n- Never expose AMI (5038) publicly.\n- Use a dedicated AMI user with minimum permissions.\n- Prefer binding to localhost or a private network interface.\n- Store credentials in environment variables (or secrets manager).\n\n### FastAGI\n\nFastAGI runs as a server process and handles AGI commands over TCP. Run a FastAGI server and configure Asterisk to call it.\n\nExample FastAGI dispatcher:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nrequire 'vendor/autoload.php';\n\nuse Fperdomo\\PhpAgi\\FastAgiDispatcher;\n\n// Handler scripts live here\n$dispatcher = new FastAgiDispatcher(\n    baseDir: __DIR__ . '/handlers',\n    dropPrivileges: true,\n    logVerboseDump: false,\n);\n\n$dispatcher-\u003ehandle();\n```\n\nConfigure Asterisk to use FastAGI in `extensions.conf`:\n\n```ini\nexten =\u003e 123,1,FastAGI(agi://your.server.ip:4573/your-script)\n```\n\n### Asterisk Manager (AMI)\n\nUse the AgiAsteriskManager class to connect to Asterisk's management interface to receive events or take actions programmatically.\n\nExample:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nrequire 'vendor/autoload.php';\n\nuse Fperdomo\\PhpAgi\\AgiAsteriskManager;\n\n// Configuration from environment variables or defaults\n$config = [\n    'server'   =\u003e getenv('AMI_HOST') ?: '127.0.0.1',\n    'port'     =\u003e (int) (getenv('AMI_PORT') ?: 5038),\n    'username' =\u003e getenv('AMI_USER') ?: 'admin',\n    'secret'   =\u003e getenv('AMI_SECRET') ?: 'amp111',\n];\n\ntry {\n    $manager = new AgiAsteriskManager(null, $config);\n    \n    // Connect to Asterisk Manager\n    if ($manager-\u003econnect()) {\n        echo \"Connected to Asterisk Manager Interface\\n\";\n        \n        // Perform actions (e.g., originate call, query status, etc.)\n        // $response = $manager-\u003esend_request('Action', ['Action' =\u003e 'Ping']);\n        \n        // Remember to disconnect when done\n        // $manager-\u003edisconnect();\n    }\n} catch (\\Throwable $e) {\n    error_log('AMI Error: ' . $e-\u003egetMessage());\n    exit(1);\n}\n```\n\n**Environment Variables:**\n\nFor security, use environment variables for sensitive configuration:\n\n```bash\nexport AMI_HOST=\"127.0.0.1\"\nexport AMI_PORT=\"5038\"\nexport AMI_USER=\"admin\"\nexport AMI_SECRET=\"your-secret-password\"\n```\n\n## Directory layout\n\nA suggested layout for this project:\n\n```\nsrc/\n  Agi.php               # Main AGI class\n  FastAgiDispatcher.php # FastAGI dispatcher\n  AgiAsteriskManager.php# Asterisk Manager (AMI) support\ncomposer.json\nREADME.md\n```\n\n## Contributing\n\nContributions are welcome. Suggested workflow:\n\n1. Fork the repository\n2. Create a feature branch: `git checkout -b feature/fooBar`\n3. Commit your changes\n4. Push to your fork\n5. Open a Pull Request\n\nTesting \u0026 CI: Ensure compatibility with PHP 8.3+; GitHub Actions or similar CI is recommended.\n\n## License\n\nThis project is released under the GNU Lesser General Public License (LGPL-2.1+), consistent with the original PHPAGI license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasterfermin02%2Fphp-agi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmasterfermin02%2Fphp-agi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasterfermin02%2Fphp-agi/lists"}