{"id":13704709,"url":"https://github.com/rtckit/php-sip","last_synced_at":"2026-01-11T16:39:32.779Z","repository":{"id":46565293,"uuid":"308205066","full_name":"rtckit/php-sip","owner":"rtckit","description":":phone: SIP Parsing/Rendering Library for PHP","archived":false,"fork":false,"pushed_at":"2023-05-22T14:25:04.000Z","size":1178,"stargazers_count":35,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-11-09T01:18:06.158Z","etag":null,"topics":["composer-library","php","rfc-3261","sip","sip-parser","telco","telecommunications","telephony","voip","voip-library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rtckit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-10-29T03:16:51.000Z","updated_at":"2024-10-10T13:22:26.000Z","dependencies_parsed_at":"2024-01-20T22:48:24.402Z","dependency_job_id":null,"html_url":"https://github.com/rtckit/php-sip","commit_stats":{"total_commits":41,"total_committers":3,"mean_commits":"13.666666666666666","dds":0.04878048780487809,"last_synced_commit":"f7bb13bdd4cb70090303801381d4e5d11787da3f"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtckit%2Fphp-sip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtckit%2Fphp-sip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtckit%2Fphp-sip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtckit%2Fphp-sip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rtckit","download_url":"https://codeload.github.com/rtckit/php-sip/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224440058,"owners_count":17311580,"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":["composer-library","php","rfc-3261","sip","sip-parser","telco","telecommunications","telephony","voip","voip-library"],"created_at":"2024-08-02T21:01:18.725Z","updated_at":"2026-01-11T16:39:32.743Z","avatar_url":"https://github.com/rtckit.png","language":"PHP","funding_links":[],"categories":["配置 Configuration","Developer Resources"],"sub_categories":["杂项 Miscellaneous","PHP Libraries"],"readme":"\u003ca href=\"#php-sip-parsingrendering-library\"\u003e\n  \u003cimg loading=\"lazy\" src=\"https://raw.github.com/rtckit/media/master/php-sip/readme-splash.png\" alt=\"php-sip\" class=\"width-full\"\u003e\n\u003c/a\u003e\n\n# PHP SIP Parsing/Rendering Library\n\n[RFC 3261](https://tools.ietf.org/html/rfc3261) compliant SIP parsing and rendering library for PHP 7.4.\n\n[![CI Status](https://github.com/rtckit/php-sip/workflows/CI/badge.svg)](https://github.com/rtckit/php-sip/actions/workflows/ci.yaml)\n[![Psalm Type Coverage](https://shepherd.dev/github/rtckit/php-sip/coverage.svg)](https://shepherd.dev/github/rtckit/php-sip)\n[![Latest Stable Version](https://poser.pugx.org/rtckit/sip/v/stable.png)](https://packagist.org/packages/rtckit/sip)\n[![Installs on Packagist](https://img.shields.io/packagist/dt/rtckit/sip?color=blue\u0026label=Installs%20on%20Packagist)](https://packagist.org/packages/rtckit/sip)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/aff5ee8e8ef3b51689c2/test_coverage)](https://codeclimate.com/github/rtckit/php-sip/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/aff5ee8e8ef3b51689c2/maintainability)](https://codeclimate.com/github/rtckit/php-sip/maintainability)\n[![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)\n\n## Quickstart\n\n#### SIP Message Parsing\n\nOnce [installed](#installation), you can parse SIP messages right away as follows:\n\n```php\n/*\n * $text holds your SIP message as a string, for example\n * $text = 'REGISTER sip:192.168.0.1 SIP/2.0 /.../';\n */\n$message = \\RTCKit\\SIP\\Message::parse($text);\n\n/* Outputs \"RTCKit\\SIP\\Request\" */\necho get_class($message) . PHP_EOL;\n\n/* Outputs something similar to:\n * Protocol version:   SIP/2.0\n * Request method:     REGISTER\n * Request URI:        sip:192.168.0.1\n * Via:                192.168.0.2:5050\n * Via branch:         z9hG4bK.eAV4o0nXr\n * From scheme:        sip\n * From user:          buzz\n * From host:          192.168.0.1\n * From tag:           SFJbQ2oWh\n * To scheme:          sip\n * To user:            buzz\n * To host:            192.168.0.1\n * Sequence number:    20\n * Call ID:            ob0EYyuyC0\n */\nprintf(\"Protocol version:   %s\" . PHP_EOL, $message-\u003eversion);\nprintf(\"Request method:     %s\" . PHP_EOL, $message-\u003emethod);\nprintf(\"Request URI:        %s\" . PHP_EOL, $message-\u003euri);\nprintf(\"Via:                %s\" . PHP_EOL, $message-\u003evia-\u003evalues[0]-\u003ehost);\nprintf(\"Via branch:         %s\" . PHP_EOL, $message-\u003evia-\u003evalues[0]-\u003ebranch);\nprintf(\"From scheme:        %s\" . PHP_EOL, $request-\u003efrom-\u003euri-\u003escheme);\nprintf(\"From user:          %s\" . PHP_EOL, $request-\u003efrom-\u003euri-\u003euser);\nprintf(\"From host:          %s\" . PHP_EOL, $request-\u003efrom-\u003euri-\u003ehost);\nprintf(\"From tag:           %s\" . PHP_EOL, $request-\u003efrom-\u003etag);\nprintf(\"To scheme:          %s\" . PHP_EOL, $request-\u003eto-\u003euri-\u003escheme);\nprintf(\"To user:            %s\" . PHP_EOL, $request-\u003eto-\u003euri-\u003euser);\nprintf(\"To host:            %s\" . PHP_EOL, $request-\u003eto-\u003euri-\u003ehost);\nprintf(\"Sequence number:    %s\" . PHP_EOL, $message-\u003ecSeq-\u003esequence);\nprintf(\"Call ID:            %s\" . PHP_EOL, $message-\u003ecallId-\u003evalue);\n```\n\n#### SIP Message Rendering\n\nRendering is the opposite action of parsing; for example, let's prepare a `200 OK` response for a `REGISTER` request:\n\n```php\n$response = new \\RTCKit\\SIP\\Response;\n$response-\u003eversion = 'SIP/2.0';\n$response-\u003ecode = 200;\n\n$response-\u003evia = new \\RTCKit\\SIP\\Header\\ViaHeader;\n$response-\u003evia-\u003evalues[0] = new \\RTCKit\\SIP\\Header\\ViaValue;\n$response-\u003evia-\u003evalues[0]-\u003eprotocol = 'SIP';\n$response-\u003evia-\u003evalues[0]-\u003eversion = '2.0';\n$response-\u003evia-\u003evalues[0]-\u003etransport = 'UDP';\n$response-\u003evia-\u003evalues[0]-\u003ehost = '192.168.0.2:5050';\n$response-\u003evia-\u003evalues[0]-\u003ebranch = 'z9hG4bK.eAV4o0nXr';\n\n$response-\u003efrom = new \\RTCKit\\SIP\\Header\\NameAddrHeader;\n$response-\u003efrom-\u003euri = new \\RTCKit\\SIP\\URI;\n$response-\u003efrom-\u003euri-\u003escheme = 'sip';\n$response-\u003efrom-\u003euri-\u003euser = 'buzz';\n$response-\u003efrom-\u003euri-\u003ehost = '192.168.0.1';\n$response-\u003efrom-\u003etag = 'SFJbQ2oWh';\n\n$response-\u003eto = new \\RTCKit\\SIP\\Header\\NameAddrHeader;\n$response-\u003eto-\u003euri = new \\RTCKit\\SIP\\URI;\n$response-\u003eto-\u003euri-\u003escheme = 'sip';\n$response-\u003eto-\u003euri-\u003euser = 'buzz';\n$response-\u003eto-\u003euri-\u003ehost = '192.168.0.1';\n$response-\u003eto-\u003etag = '8cQtUyH6N5N9K';\n\n$response-\u003ecSeq = new \\RTCKit\\SIP\\Header\\CSeqHeader;\n$response-\u003ecSeq-\u003esequence = 20;\n$response-\u003ecSeq-\u003emethod = 'REGISTER';\n\n$response-\u003ecallId = new \\RTCKit\\SIP\\Header\\CallIdHeader;\n$response-\u003ecallId-\u003evalue = 'ob0EYyuyC0';\n\n$response-\u003emaxForwards = new \\RTCKit\\SIP\\Header\\ScalarHeader;\n$response-\u003emaxForwards-\u003evalue = 70;\n\n$response-\u003econtact = new \\RTCKit\\SIP\\Header\\ContactHeader;\n$response-\u003econtact-\u003evalues[0] = new \\RTCKit\\SIP\\Header\\ContactValue;\n$response-\u003econtact-\u003evalues[0]-\u003euri = new \\RTCKit\\SIP\\URI;\n$response-\u003econtact-\u003evalues[0]-\u003euri-\u003escheme = 'sip';\n$response-\u003econtact-\u003evalues[0]-\u003euri-\u003euser = 'buzz';\n$response-\u003econtact-\u003evalues[0]-\u003euri-\u003ehost = '192.168.0.2';\n$response-\u003econtact-\u003evalues[0]-\u003euri-\u003eport = 5050;\n$response-\u003econtact-\u003evalues[0]-\u003euri-\u003etransport = 'udp';\n$response-\u003econtact-\u003evalues[0]-\u003eexpires = 3600;\n\n$response-\u003euserAgent = new \\RTCKit\\SIP\\Header\\Header;\n$response-\u003euserAgent-\u003evalues[0] = 'MyDeskPhone/1.0.0';\n\n/* Outputs:\n * SIP/2.0 200 OK\n * Via: SIP/2.0/UDP 192.168.0.2:5050;branch=z9hG4bK.eAV4o0nXr\n * From: \u003csip:buzz@192.168.0.1\u003e;tag=SFJbQ2oWh\n * To: \u003csip:buzz@192.168.0.1\u003e;tag=8cQtUyH6N5N9K\n * Contact: \u003csip:buzz@192.168.0.2:5050;transport=udp\u003e;expires=3600\n * Call-ID: ob0EYyuyC0\n * CSeq: 20 REGISTER\n * Max-Forwards: 70\n * User-Agent: MyDeskPhone/1.0.0\n */\necho $response-\u003erender();\n```\n\n#### SIP Message Stream Parsing\n\nIf your use case involves a continuous data stream rather than individual messages, the `StreamParser` class can help; this is particularly useful for analyzing SIP trace files or packet captures, parsing SIP traffic over TCP etc.\n\n```php\n/* Instantiate the Stream Parser */\n$parser = new \\RTCKit\\SIP\\StreamParser;\n\n$fp = fopen(/.../);\n\nwhile (!feof($fp)) {\n    $bytes = fread($fp, 256);\n\n    /* The actual input string ($bytes) can be retrieved from any stream-like source */\n    if ($parser-\u003eprocess($bytes, $messages) === \\RTCKit\\SIP\\StreamParser::SUCCESS) {\n        foreach ($messages as $message) {\n            /*\n             * $message is either a Request or a Response object, using\n             * the same structure as messages returned by Message::parse()\n             */\n        }\n    }\n}\n```\n\nLastly, the provided [examples](examples) are a good starting point.\n\n## Requirements\n\n**RTCKit\\SIP** is compatible with PHP 7.4+ and has no external library and extension dependencies.\n\n## Installation\n\nYou can add the library as project dependency using [Composer](https://getcomposer.org/):\n\n```sh\ncomposer require rtckit/sip\n```\n\nIf you only need the library during development, for instance when used in your test suite, then you should add it as a development-only dependency:\n\n```sh\ncomposer require --dev rtckit/sip\n```\n\n## Tests\n\nTo run the test suite, clone this repository and then install dependencies via Composer:\n\n```sh\ncomposer install\n```\n\nThen, go to the project root and run:\n\n```bash\nphp -d memory_limit=-1 ./vendor/bin/phpunit -c ./etc/phpunit.xml.dist\n```\n\n### Static Analysis\n\nIn order to ensure high code quality, **RTCKit\\SIP** uses [PHPStan](https://github.com/phpstan/phpstan) and [Psalm](https://github.com/vimeo/psalm):\n\n```sh\nphp -d memory_limit=-1 ./vendor/bin/phpstan analyse -c ./etc/phpstan.neon -n -vvv --ansi --level=max src\nphp -d memory_limit=-1 ./vendor/bin/psalm --config=./etc/psalm.xml\n```\n\n## License\n\nMIT, see [LICENSE file](LICENSE).\n\n### Acknowledgments\n\n* [SIP Protocol Contributors/IETF Trust](https://www.ietf.org/standards/rfcs/)\n* [PROTOS SIP Test Material](https://www.ee.oulu.fi/research/ouspg/PROTOS_Test-Suite_c07-sip) - Oulu University Secure Programming Group, Finland\n* [lioneagle/sipparser Test Material](https://github.com/lioneagle/sipparser/blob/master/src/testdata/sip_msg.txt) (MIT license)\n\n### Contributing\n\nBug reports (and small patches) can be submitted via the [issue tracker](https://github.com/rtckit/php-sip/issues). Forking the repository and submitting a Pull Request is preferred for substantial patches.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtckit%2Fphp-sip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frtckit%2Fphp-sip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtckit%2Fphp-sip/lists"}