{"id":18479397,"url":"https://github.com/yggverse/nps-php","last_synced_at":"2025-05-13T18:42:12.071Z","repository":{"id":235875502,"uuid":"791437057","full_name":"YGGverse/nps-php","owner":"YGGverse","description":"PHP 8 Library for NPS Protocol","archived":false,"fork":false,"pushed_at":"2024-04-24T20:04:36.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-24T20:09:20.606Z","etag":null,"topics":["composer","nex","nex-protocol","nps","nps-php","nps-protocol","nps-protocol-server","nps-server","server","smallweb","tinyweb"],"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/YGGverse.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-24T18:04:34.000Z","updated_at":"2024-04-24T20:04:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"ae27e7bf-5b74-4922-8533-8e314ce0e386","html_url":"https://github.com/YGGverse/nps-php","commit_stats":null,"previous_names":["yggverse/nps-php"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YGGverse%2Fnps-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YGGverse%2Fnps-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YGGverse%2Fnps-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YGGverse%2Fnps-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YGGverse","download_url":"https://codeload.github.com/YGGverse/nps-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254005904,"owners_count":21998341,"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","nex","nex-protocol","nps","nps-php","nps-protocol","nps-protocol-server","nps-server","server","smallweb","tinyweb"],"created_at":"2024-11-06T12:14:35.764Z","updated_at":"2025-05-13T18:42:12.046Z","avatar_url":"https://github.com/YGGverse.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"**Archived!**\n\nUse [Ratchet](https://github.com/ratchetphp/Ratchet) `IoServer` - asynchronous WebSocket in PHP as more featured replacement to this library.\n\n# nps-php\n\nPHP 8 / Composer Library for NPS Protocol\n\nLike Titan for Gemini, NPS is the satellite for NEX protocol (see also [nex-php](https://github.com/YGGverse/nex-php))\\\nit listen for single dot in line to signal the package ending.\n\n## Specification\n\n`nex://nightfall.city/nps/`\n\n## Usage\n\n```\ncomposer require yggverse/nps\n```\n\n## Server\n\nBuild interactive server instance to listen NPS protocol connections!\n\n``` php\n$server = new \\Yggverse\\Nps\\Server;\n```\n\nProvide optional `host`, `port`, `size`, `line` and `live` arguments in constructor:\n\n``` php\n$server = new \\Yggverse\\Nps\\Server('127.0.0.1', 1915);\n```\n\nAlternatively, use following setters after object initiation\n\n#### Server::setHost\n\nBind server host to listen incoming connections, `127.0.0.1` by default\n\n#### Server::getHost\n\nGet current server host\n\n#### Server::setPort\n\nBind server port to listen incoming connections, `1915` by default\n\n#### Server::getPort\n\nGet current server port\n\n#### Server::setSize\n\nSet total content length limit by [mb_strlen](https://www.php.net/manual/en/function.mb-strlen.php), `0` by default (unlimited)\n\n#### Server::getSize\n\nGet current content length limit\n\n#### Server::setLine\n\nSet packet line limit in bytes passing to [fread](https://www.php.net/manual/en/function.fread.php#length), `1024` by default\n\n#### Server::getLine\n\nGet current packet line limit\n\n#### Server::setLive\n\nSet server status `true`|`false` to shutdown immediately\n\n#### Server::getLive\n\nGet current server status\n\n#### Server::setWelcome\n\nDefine application logic on peer connection established\n\n``` php\n$server-\u003esetWelcome(\n    function (\n        string $connect\n    ): ?string\n    {\n        printf(\n            \"connected: %s\\n\\r\",\n            $connect\n        );\n\n        return sprintf(\n            \"welcome, %s\\n\\r\",\n            $connect\n        );\n    }\n);\n```\n\n#### Server::getWelcome\n\nGet current `Welcome` function, `null` by default\n\n#### Server::setPending\n\nDefine application logic on peer make initial request\n\n``` php\n$server-\u003esetPending(\n    function (\n        string $request,\n        string $connect\n    ): ?string\n    {\n        printf(\n            'connection: %s requested: %s',\n            $connect,\n            $request,\n        );\n\n        return sprintf(\n            'received: %s',\n            $request\n        );\n    }\n);\n```\n\n#### Server::getPending\n\nGet current `Pending` function, `null` by default\n\n#### Server::setHandler\n\nDefine basic application logic on complete packet received\n\n* could be also defined as [Server::start](https://github.com/YGGverse/nps-php#serverstart) argument\n\n``` php\n$server-\u003esetHandler(\n    function (\n          bool $success,\n        string $content,\n        string $request,\n        string $connect\n    ): ?string\n    {\n        printf(\n            'connection: %s request: %s',\n            $connect,\n            $request\n        );\n\n        if ($success)\n        {\n            var_dump(\n                $content\n            );\n        }\n\n        return 'thank you!';\n    }\n);\n```\n\n#### Server::getHandler\n\nGet current `Handler` function, `null` by default\n\n#### Server::start\n\nRun server object\n\n``` php\n$server-\u003estart();\n```\n\nOptionally, define handler function as the argument to process application logic dependent of client request\n\n``` php\n$server-\u003estart(\n    function (\n          bool $success,\n        string $content,\n        string $request,\n        string $connect\n    ): ?string\n    {\n        printf(\n            'connection: %s request: %s',\n            $connect,\n            $request\n        );\n\n        if ($success)\n        {\n            var_dump(\n                $content\n            );\n        }\n\n        return 'thank you!'; // null|string response\n    }\n);\n```\n\n#### Server::stop\n\nStop server instance.\n\nSame to `Server::setLive(false)`\n\n### Testing\n\n1. `nc 127.0.0.1 1915` - connect server using `nc`\n2. `test` - enter the target path\n3. `YOUR MESSAGE GOES HERE` - enter the message text\n4. `.` - commit package with dot\n\nTo send any file:\n\n``` file.txt\ntest\n╦ ╦╔═╗╔═╗╔╦╗╦═╗╔═╗╔═╗╦╦\n╚╦╝║ ╦║ ╦ ║║╠╦╝╠═╣╚═╗║║\n ╩ ╚═╝╚═╝═╩╝╩╚═╩ ╩╚═╝╩╩═╝\n.\n```\n\n`cat file.txt | nc 127.0.0.1 1915`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyggverse%2Fnps-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyggverse%2Fnps-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyggverse%2Fnps-php/lists"}