{"id":15578465,"url":"https://github.com/phvia/firman","last_synced_at":"2025-03-29T07:42:54.010Z","repository":{"id":57041228,"uuid":"140418704","full_name":"phvia/firman","owner":"phvia","description":"PHP Multi-process and Non-blocking I/O Socket Library.","archived":false,"fork":false,"pushed_at":"2018-10-10T04:31:02.000Z","size":48,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-03T21:35:16.094Z","etag":null,"topics":["firman","multi-process","non-blocking-io","php-socket","php7","socket"],"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/phvia.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}},"created_at":"2018-07-10T10:56:05.000Z","updated_at":"2021-07-01T19:39:25.000Z","dependencies_parsed_at":"2022-08-24T01:10:36.521Z","dependency_job_id":null,"html_url":"https://github.com/phvia/firman","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phvia%2Ffirman","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phvia%2Ffirman/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phvia%2Ffirman/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phvia%2Ffirman/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phvia","download_url":"https://codeload.github.com/phvia/firman/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246156011,"owners_count":20732357,"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":["firman","multi-process","non-blocking-io","php-socket","php7","socket"],"created_at":"2024-10-02T19:10:39.514Z","updated_at":"2025-03-29T07:42:53.986Z","avatar_url":"https://github.com/phvia.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Firman\n\nPHP multi-process and non-blocking I/O library.\n\n## Dependency\n* PHP\u003e=7. (for new features and high performance)\n* PCNTL extension. (compile PHP with `--enable-pcntl` option to enable)\n* Sockets extension. (compile PHP with `--enable-sockets` option to enable)\n\n## Install\n```shell\n$ composer require phvia/firman:dev-master\n```\n\n## Run example\n\n* Show usage  \n```shell\n$ php /path/to/firman/examples/via_websocket_serv_builtin.php\n\nFirman package 0.0.1\n\nUsage:\n  command [options] [arguments]\n\nOptions:\n  -h, --help            Display this help message\n  -q, --quiet           Do not output any message\n  -V, --version         Display this application version\n      --ansi            Force ANSI output\n      --no-ansi         Disable ANSI output\n  -n, --no-interaction  Do not ask any interactive question\n  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug\n\nAvailable commands:\n  help     Displays help for a command\n  list     Lists commands\n  restart  Restart Firman server\n  start    Start Firman server\n  stop     Stop Firman server\n```\n\n* Show usage detail\n```shell\n$ php /path/to/firman/examples/via_websocket_serv_builtin.php start -h\n\nUsage:\n  start [options]\n\nOptions:\n  -e, --env=ENV         The Environment name (support: dev, prod) [default: \"dev\"]\n  -h, --help            Display this help message\n  -q, --quiet           Do not output any message\n  -V, --version         Display this application version\n      --ansi            Force ANSI output\n      --no-ansi         Disable ANSI output\n  -n, --no-interaction  Do not ask any interactive question\n  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug\n\nHelp:\n  Start Firman server\n```\n\n* Process control\n```shell\n# After start server, you can access examples/ws.html in web browser\n$ php examples/via_websocket_serv_builtin.php start\n\n# Restart Firman server\n$ php examples/via_websocket_serv_builtin.php restart\n\n# Stop Firman server\n$ php examples/via_websocket_serv_builtin.php stop\n```\n\n* Run in daemon\n```shell\n$ php /path/to/firman/xxx.php start --env=prod\n# OR\n$ php /path/to/firman/xxx.php start --eprod\n$\n$ ps auxf | grep Firman\n```\n\n## Do it yourself\n\n* Simplest configure\n```php\ninclude '/path/to/vendor/autoload.php';\n\n(new \\Firman\\Server('tcp://0.0.0.0:8080'))-\u003erun();\n```\n\n* Full configure\n```php\ninlcude '/path/to/vendor/autoload.php';\n\n$server = new \\Firman\\Server();\n\n$socket = 'tcp://0.0.0.0:8080';\n\n$server\n    // Parameter.\n    \n    // optional, default is 1\n    // Set child process number\n    -\u003esetCount(1)\n    \n    // optional, can also be in constructor\n    // Set socket\n    -\u003esetSocket($socket)\n    \n    // optional, default is Firman\n    // Set process title\n    -\u003esetProcessTitle('Firman')\n    \n    // optional, default is /tmp\n    // Set the path of file saved ppid\n    -\u003esetPpidPath('/tmp')\n    \n    // optional, default is 100\n    // Set socket backlog number\n    -\u003esetBacklog(100)\n    \n    // optional, default is 200\n    // Set select system call timeout value\n    -\u003esetSelectTimeout(5)\n    \n    // optional, default is 60\n    // Set accept timeout value\n    -\u003esetAcceptTimeout(10)\n\n    // Event callback.\n    \n    // optional, when client connected with server, callback trigger.\n    // Set connection event callback task\n    -\u003eonConnection(function($connection) {\n        echo \"New client connected.\" . PHP_EOL;\n    })\n    \n    // optional, when client send message to server, callback trigger.\n    // Set message event callback task\n    -\u003eonMessage(function($connection) {\n        // implement your logic\n    })\n    \n    // Run server.\n    \n    -\u003erun();\n```\n\n## Server workflow explain\n\n* Check environment.  \n* Parse command.  \n* Initialize master process information.    \n*   Fork child process, install signal for child, poll on child.  \n*   Create socket server (like: create socket, bind, listen, set option).  \n* Block on master, monitor any child process and restart who exited.  \n\n## Tests\n```shell\n$ ./vendor/bin/phpunit --bootstrap=vendor/autoload.php tests\n```\n\n## Todo\nOur position is focus on socket :  \n\n* Implement protocol parse built-in.  \n* Support Unix domain, UDP, ect.  \n* Robustness.\n\n## Resources:\nComposer Document: https://getcomposer.org/doc/  \n\nSymfony Console Component: http://symfony.com/doc/current/components/console.html\n\n## Contribute:  \nAny pull requests to improve **phvia/firman** are welcome.  \n\nCoding style follow PSR2: https://www.php-fig.org/psr/psr-2/  \nUsing PHP_CodeSniffer tool: https://github.com/squizlabs/PHP_CodeSniffer  \nRunning check: `php phpcs.phar --standard=psr2 ./`  \n\nRecommend Coding Standards: https://symfony.com/doc/current/contributing/code/standards.html\n\n## Group\nQQ group: 377154148\n\n## License\n[MIT](https://github.com/phvia/firman/blob/master/LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphvia%2Ffirman","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphvia%2Ffirman","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphvia%2Ffirman/lists"}