{"id":28420425,"url":"https://github.com/greenfieldtech-nirs/phpari","last_synced_at":"2025-06-28T13:31:47.603Z","repository":{"id":20374168,"uuid":"23649623","full_name":"greenfieldtech-nirs/phpari","owner":"greenfieldtech-nirs","description":"A Class Library enabling Asterisk ARI functionality for PHP","archived":false,"fork":false,"pushed_at":"2021-11-04T15:24:19.000Z","size":876,"stargazers_count":91,"open_issues_count":6,"forks_count":55,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-06-05T04:44:55.074Z","etag":null,"topics":["asterisk","composer","php","stasis"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"octopress/octobopper","license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/greenfieldtech-nirs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-04T05:26:53.000Z","updated_at":"2025-03-02T00:12:06.000Z","dependencies_parsed_at":"2022-07-21T07:48:04.492Z","dependency_job_id":null,"html_url":"https://github.com/greenfieldtech-nirs/phpari","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/greenfieldtech-nirs/phpari","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greenfieldtech-nirs%2Fphpari","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greenfieldtech-nirs%2Fphpari/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greenfieldtech-nirs%2Fphpari/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greenfieldtech-nirs%2Fphpari/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/greenfieldtech-nirs","download_url":"https://codeload.github.com/greenfieldtech-nirs/phpari/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greenfieldtech-nirs%2Fphpari/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262437870,"owners_count":23311042,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["asterisk","composer","php","stasis"],"created_at":"2025-06-05T02:17:26.290Z","updated_at":"2025-06-28T13:31:47.597Z","avatar_url":"https://github.com/greenfieldtech-nirs.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"phpari\n======\n\nA Class Library enabling Asterisk ARI functionality for PHP\n\nDependencies\n------------\nThese are the minimum requirements to have phpari installed on your server:\n\n** PHP \u003e= 5.3.9\n\n** Composer\n\n** PHP OpenSSL Module to connect using SSL (wss:// uris)\n\nAdditional dependencies are installed via Composer, these include:\n\n** Reactphp   (http://reactphp.org/)\n\n** ZF2 Logger (http://framework.zend.com/manual/2.0/en/modules/zend.log.overview.html)\n\nInstallation\n------------\nThe recommended method of installation is using Composer. Add the following to your composer.json file:\n\n```\n{\n    \"require\": {\n        \"php\": \"\u003e=5.3.9\",\n        \"educoder/pest\": \"1.0.0\",\n        \"devristo/phpws\": \"dev-master\",\n        \"greenfieldtech-nirs/phpari\": \"dev-master\"\n    }\n}\n```\n\nWe recommend using the \"dev-master\" version at this point in time, as we are still under heavy development and testing.\n\nConfiguring phpari.ini\n----------------------\nThe phpari.ini file is our primary configuration file. You can define your own, just make sure to initiate your phpari object correctly. \nThe files' contents is as following:\n\n```\n[general]\ndebug=0\nlogfile=console ; console for direct console output, filename for file based logging\n\n[asterisk_ari]\nusername=testuser\npassword=testing\nhost=your_asterisk_server_ip_or_fqdn\nport=your_asterisk_http_port\nendpoint=/ari\ntransport=ws ; ws for none encrypted, wss for encrypted (currently, only ws is supported)\n\n[asterisk_manager]\nusername=amiuser\npassword=amipassword\nhost=127.0.0.1\nport=5038\n```\n\nAs you may notice, we already carry an Asterisk Manager configuration in there - this will be used in the future to provide\nan Asterisk manager connector object as well.\n\nVerify functionality\n--------------------\nThe simplest way to verify that phpari is installed correctly is by using it. Here is a minimal script to ensure you every installed correctly:\n\n```php\nrequire_once(\"vendor/autoload.php\");\n\necho \"Starting ARI Connection\\n\";\n$ariConnector = new phpari();\necho \"Active Channels: \" . json_encode($ariConnector-\u003echannels()-\u003echannel_list()) . \"\\n\";\necho \"Ending ARI Connection\\n\";\n\n```\n\nThe output should resemble the following:\n\n```\n[root@ari agi-bin]# php test.php\nStarting ARI Connection\nActive Channels: []\nEnding ARI Connection\n```\n\nError Handling within PHPARI\n--------------------\nIn order to allow for better error handling, we've decided to hold two variables, within the initiated phpari object. These are \"lasterror\" and \"lasttrace\". \nWhen an error occures, in any of the phpari module requests, be it a PEST error or another, an exception is thrown internally. In order not to break your applications,\nwe will return a FALSE value, while populating the \"lasterror\" and \"lasttrace\" variables.\n\nFor example:\n\n```php\n    try {\n        $conn = new phpari(\"hello-world\"); //create new object\n        $app  = new applications($conn);\n\n        $result=$app-\u003eapplications_list();\n\n        if ((!$result) \u0026\u0026 (count($result)))\n            throw new Exception(\"phpari error occured\", 503);\n\n        echo json_encode($result);\n        exit(0);\n\n    } catch (Exception $e) {\n        echo \"Error: \" . $conn-\u003elasterror. \"\\n\";\n        echo \"Trace: \" . $conn-\u003elasttrace. \"\\n\";\n    }\n```\n\nIn the above case, we try to issue an \"applications\" GET request over to our Asterisk server. In case of an error, the \napplications object will return a FALSE value, while populating the \"lasterror\" and \"lasttrace\" variables. Here is a sample\noutput, for a case where the \"port\" configuration is wrong, in phpari.ini:\n\n```\n$ php ApplicationList.php\nError: Failed connect to 178.62.XXX.XXX:8080; No error\nTrace: #0 C:\\Users\\nirsi_000\\Documents\\phpari\\vendor\\educoder\\pest\\Pest.php(128): Pest-\u003edoRequest(Resource id #60)\n#1 C:\\Users\\nirsi_000\\Documents\\phpari\\src\\interfaces\\applications.php(58): Pest-\u003eget('/applications')\n#2 C:\\Users\\nirsi_000\\Documents\\phpari\\examples\\ApplicationList.php(33): applications-\u003eapplications_list()\n#3 {main}\n```\n\nBasic Stasis application programming\n------------------------------------\nStasis is an event driven environment, which isn't really the native environment for PHP. However, thanks to PHP 5.3 and the React library, it is possible to write a \"callback\" based web socket client.\nThe following example shows how this can be done - the complete example is under examples/BasicStasisApplication.php.\n\nFirst, we need to setup our basic Stasis connection to Asterisk:\n\n```php\n    class BasicStasisApplication\n    {\n\n        private $ariEndpoint;\n        private $stasisClient;\n        private $stasisLoop;\n        private $phpariObject;\n        private $stasisChannelID;\n        private $dtmfSequence = \"\";\n\n        public $stasisLogger;\n\n        public function __construct($appname = NULL)\n        {\n            try {\n                if (is_null($appname))\n                    throw new Exception(\"[\" . __FILE__ . \":\" . __LINE__ . \"] Stasis application name must be defined!\", 500);\n\n                $this-\u003ephpariObject = new phpari($appname);\n\n                $this-\u003eariEndpoint  = $this-\u003ephpariObject-\u003eariEndpoint;\n                $this-\u003estasisClient = $this-\u003ephpariObject-\u003estasisClient;\n                $this-\u003estasisLoop   = $this-\u003ephpariObject-\u003estasisLoop;\n                $this-\u003estasisLogger = $this-\u003ephpariObject-\u003estasisLogger;\n                $this-\u003estasisEvents = $this-\u003ephpariObject-\u003estasisEvents;\n            } catch (Exception $e) {\n                echo $e-\u003egetMessage();\n                exit(99);\n            }\n        }\n```\n\nNote this, the constructor will normally return no errors for this stage, as we are mearly building the required objects, not connecting to Asterisk yet.\nNow, we need to define our Stasis Connection Handler:\n\n```php\n        public function StasisAppConnectionHandlers()\n        {\n            try {\n                $this-\u003estasisClient-\u003eon(\"request\", function ($headers) {\n                    $this-\u003estasisLogger-\u003enotice(\"Request received!\");\n                });\n\n                $this-\u003estasisClient-\u003eon(\"handshake\", function () {\n                    $this-\u003estasisLogger-\u003enotice(\"Handshake received!\");\n                });\n\n                $this-\u003estasisClient-\u003eon(\"message\", function ($message) {\n                    $event = json_decode($message-\u003egetData());\n                    $this-\u003estasisLogger-\u003enotice('Received event: ' . $event-\u003etype);\n                    $this-\u003estasisEvents-\u003eemit($event-\u003etype, array($event));\n                });\n\n            } catch (Exception $e) {\n                echo $e-\u003egetMessage();\n                exit(99);\n            }\n        }\n```\n\nNote that we will be ommiting an Event for any additional Asterisk Stasis \"message\" that is received. \nNow, we need to actually build our connection to Asterisk:\n\n```php\n        public function execute()\n        {\n            try {\n                $this-\u003estasisClient-\u003eopen();\n                $this-\u003estasisLoop-\u003erun();\n            } catch (Exception $e) {\n                echo $e-\u003egetMessage();\n                exit(99);\n            }\n        }\n```\n\nOur main script body would be the following:\n\n```php\n    $basicAriClient = new BasicStasisApplication(\"hello-world\");\n\n    $basicAriClient-\u003estasisLogger-\u003einfo(\"Starting Stasis Program... Waiting for handshake...\");\n    $basicAriClient-\u003eStasisAppEventHandler();\n\n    $basicAriClient-\u003estasisLogger-\u003einfo(\"Connecting... Waiting for handshake...\");\n    $basicAriClient-\u003eexecute();\n```\n\nThat's it - this is your most basic Stasis application. We suggest that you now take a look at examples/BasicStasisApplication.php to see the entire code in action.\n\nReporting Issues\n--------------------\nPlease report issues directly via the Github project page.\n\nContibuting Code\n----------------\nWe are very open when it comes to people contributing code to this project. In order to make life easier, here is the preferred method to contribute code:\n\nFor bug fixes and security updates in Master branch:\n\n  1. Fork the Master Branch into your own personal Github account \n  2. Update your local fork\n  3. Generate a pull request from your own fork over to our Master Branch\n\nFor new features and improvement:\n\n  1. Fork the Development Branch into your own personal Github account\n  2. Update your local fork\n  3. Generate a pull request from your own fork over to our development branch\n\nWe will do our best to go over the various contributions as fast as possible. Bug fixes and security updates will be handled faster - feature improvements will be added to the next major release.\n\nOur IDE of choice is phpStorm from JetBrains (http://www.jetbrains.com/phpstorm/) - we use the default styling, so no need to change that. If you use a different IDE, please make sure you update your IDE to support the internal styling of the project, so that you don't break the general code styling. \n\nMake sure to document your code - once it's merged in, we will need to keep working on your code, so please make sure your documentation will be clear and concise, so we can continue your work (as required). \n\nOur objective is to involve the community as much as possible, so feel free to jump in and assist. Contibutions to the project will automatically put your name into the README.md file, so that everybody will see your coolness and greatness supporting the Open Source movement and the continuation of this project.\n\nRelease Policy\n--------------\nReleasing code into the Open Source is always a challenge, it can be both confusing and dawnting at the same time. In order to make life simple with version numbers, here is our projected release policy (it may change in the future).\n\nEvery version will be marked with a Major.Minor.Patch version numbering scheme. \n\nA major release will be released once the code of the library is stable and battle tested. How long does that take? good question, we don't know. Currently, our major release version is 0 - we are still in active development.\n\nA minor release will be released once the code of the library is stable and had been introduced with a significant number of fixes and modifications, and been regressed by several members of the community. \n\nA patch release will be released once the code of the library is stable and had been introduced with minor modifications. These modifications will normally include bug fixes and security updates.\n\nFeature enhancements will only be merged into minor releases, not into patch releases.\n\nTeam Members and Contributors\n------------------------------\nThe following list includes names and aliases for people who had something to do with the creation/maintenance of this library. It takes alot of resources to maintain an Open Source project, thus, we will always do our best to make sure contributions and tested and merged as fast as possible.\n\n    Nir Simionovich, https://github.com/greenfieldtech-nirs\n    Leonid Notik, https://github.com/lnotik\n    Scott Griepentrog, https://github.com/stgnet\n    Matak, https://github.com/matak\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreenfieldtech-nirs%2Fphpari","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreenfieldtech-nirs%2Fphpari","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreenfieldtech-nirs%2Fphpari/lists"}