{"id":13520148,"url":"https://github.com/gotzmann/comet","last_synced_at":"2025-05-15T21:03:04.362Z","repository":{"id":40001948,"uuid":"254647785","full_name":"gotzmann/comet","owner":"gotzmann","description":"Modern PHP framework for building blazing fast REST APIs and microservices","archived":false,"fork":false,"pushed_at":"2025-03-05T12:07:15.000Z","size":954,"stargazers_count":680,"open_issues_count":4,"forks_count":52,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-05-14T18:17:43.486Z","etag":null,"topics":["api","comet","framework","http-client","http-server","php","php-frameworks","psr-7","rest-api","slimphp","workerman"],"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/gotzmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2020-04-10T13:58:16.000Z","updated_at":"2025-05-05T20:15:55.000Z","dependencies_parsed_at":"2025-05-15T21:02:56.944Z","dependency_job_id":null,"html_url":"https://github.com/gotzmann/comet","commit_stats":{"total_commits":193,"total_committers":2,"mean_commits":96.5,"dds":"0.010362694300518172","last_synced_commit":"04d2ab99fa0587725a508719100d751dc1909480"},"previous_names":[],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotzmann%2Fcomet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotzmann%2Fcomet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotzmann%2Fcomet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gotzmann%2Fcomet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gotzmann","download_url":"https://codeload.github.com/gotzmann/comet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254422754,"owners_count":22068678,"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":["api","comet","framework","http-client","http-server","php","php-frameworks","psr-7","rest-api","slimphp","workerman"],"created_at":"2024-08-01T05:02:12.684Z","updated_at":"2025-05-15T21:03:04.300Z","avatar_url":"https://github.com/gotzmann.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"600\" height=\"250\" src=\"docs/logo.png\"\u003e\n\u003c/p\u003e\n\n# Comet\n\nComet is a modern PHP framework for building blazing fast REST APIs, CRUDs, admin panels, and microservices.\n\n## What's new in Comet v2\n\n- Performance improvements - up to 20-30% faster than first version!\n- Embedded secure web-server to serve static content like images, CSS styles and JS scripts\n- Extended session support for complex authentication and authorization services\n- Hassle-free out-of-the-box integration with a full-featured auth library\n\n## Superpowers at your disposal\n\n- Blazing fast with 100K HTTP requests per second and ~0.1 ms latency on commodity cloud hardware\n- Really cross-platform, works like a charm on Linux, MacOS and Windows 7/10\n- Embedded web-server to serve static content like CSS/JS and images  \n- Integration with full-featured auth library [Comet\\Auth](https://github.com/gotzmann/auth) for users management\n- Embedded validation and testing features you could use with easy to create robust software  \n- Based on bullet-proof components from Guzzle, SlimPHP and Workerman\n- Extendable with Composer: use ORM and templating engine of your choice (Eloquent and Twig are recommended)\n- PSR compliant with native implementations of all PSR-7 interfaces and PHP sessions abstraction\n- Has its own efficient HTTP client with simple programming interface \n\n## Standing on the shoulders of giants\n\nComet combines all superpowers of Slim PHP, Guzzle and Workerman and mix its own magic to achieve 10x speed up.\n\n[Slim](https://github.com/slimphp/Slim) is a micro-framework that helps write web applications and APIs based on modern PSR standards.\n\n[Guzzle](https://github.com/guzzle) is a set of PHP components to work with HTTP/1.1 and HTTP/2 services.\n\n[Workerman](https://github.com/walkor/Workerman) is an asynchronous event-driven framework to build fast and scalable network applications. \n\nComet allows you natively to use all the classes and methods of the Slim framework: http://www.slimframework.com/docs/v4/\n\n### Performance\n\nPHP is often criticized for its low throughput and high latency, but that is not necessarily true for modern frameworks. \nLet's see how Comet outperforms others.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/performance-1000.jpg\"\u003e\n\u003c/p\u003e\n\n\u003ch5 align=\"center\"\u003e\n  Benchmarking stripped versions of frameworks with no ORM under 1,000 concurrent connections\n\u003c/h5\u003e\n\nAs you can see, the right architecture provides it with a tenfold advantage over Symfony and other popular frameworks. \n\n### Latency\n\nHow long it takes to get a response from an API often is even more important than overall service throughput. And that is \nwhere Comet really shines.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/latency-1.jpg\"\u003e\n\u003c/p\u003e\n\n\u003ch5 align=\"center\"\u003e\n  Response latency of minimal versions of popular PHP frameworks under series of serial web requests\n\u003c/h5\u003e\n\nComet provides sub-millisecond latency for typical scenarios. Even under hard pressure of thousand concurrent connections \nit can compete with frameworks of compiled platforms like Go and Java.\n\n### Too good to be true? \n\nYou may run all benchmarks on your own to be sure that the charts are not a scam: https://github.com/gotzmann/benchmarks\n\n## Basics\n\n### Installation\n\nIt is recommended that you use [Composer](https://getcomposer.org/) to install Comet.\n\n```bash\n$ composer require gotzmann/comet\n```\n\nThis will install the framework itself and all required dependencies. Comet requires PHP 7.2 or newer.\n\n### Hello Comet\n\nCreate a single app.php file in the project root folder with the following content:\n\n```php\n\u003c?php\nrequire_once __DIR__ . '/vendor/autoload.php';\n\n$app = new Comet\\Comet();\n\n$app-\u003eget('/hello', \n    function ($request, $response) {              \n        return $response\n            -\u003ewith(\"Hello, Comet!\");\n});\n\n$app-\u003erun();\n```\n\nStart it from the command line:\n\n```bash\n$ php app.php start\n```\n\nThen open the browser and type in the default address http://localhost. You'll see hello from Comet.\n\n### Simple JSON Response\n\nLet's start the Comet server listening on a custom host:port and returning a JSON payload.\n\n```php\n\u003c?php\nrequire_once __DIR__ . '/vendor/autoload.php';\n\n$app = new Comet\\Comet([\n    'host' =\u003e '127.0.0.1',\n    'port' =\u003e 8080,\n]);\n\n$app-\u003eget('/json', \n    function ($request, $response) {        \n        $data = [ \"message\" =\u003e \"Hello, Comet!\" ];\n        return $response\n            -\u003ewith($data);\n});\n\n$app-\u003erun();\n```\n\nStart the browser or Postman and see the JSON response from GET http://127.0.0.1:8080.\n\n## Authorization, authentication, ACL and users management\n\nThere special full-featured [Comet/Auth](https://github.com/gotzmann/auth) library which allows you to create secure and \nsophisticated scenarios for user registration, email checking, password management, role-based access and so on.\n\nPlease refer for the corresponding documentation on how to use Comet\\Auth in your own projects.\n\n## Validation\n\nComet's validation engine is based on the clean yet powerful [Rakit Validation](https://github.com/rakit/validation) library.\n\nTo start using Comet validation in your own project, specify the following use statement:\n\n```php\nuse Comet\\Validator;\n```\n\nYou can use different predefined and user-defined rules, custom error messages, and controller logic to deal with errors. \nLook at this example:\n\n```php\n$payload = (string) $request-\u003egetBody();\n\n// Prior to 7.3 PHP does not support RFC3339_EXTENDED (milliseconds are broken)\n$version = explode('.', PHP_VERSION);\n$dateFormat = ($version[0] == 7 \u0026\u0026 $version[1] \u003e= 3) ? \\DateTime::RFC3339_EXTENDED : \"Y-m-d?H:i:s.???P\";\n\n$rules = [\n    'paymentOrderId' =\u003e 'required',\n    'customerId'     =\u003e 'required|uuid',\n    'clientKey'      =\u003e 'required|alpha_dash',\n    'paymentDate'    =\u003e 'required|date:' . $dateFormat,\n];\n\n$messages = [\n    'required'   =\u003e 'field is required',\n    'alpha_num'  =\u003e 'only alphabet and digits allowed',\n    'alpha_dash' =\u003e 'only alphabet chars, digits and dashes are allowed',\n    'uuid'       =\u003e 'UUID is wrong',\n    'date'       =\u003e 'should be RFC3339 date',\n];        \n\n$validator = new Validator;\n$validation = $validator-\u003evalidate($payload, $rules, $messages);        \nif (count($validation-\u003egetErrors())) {\n    return $response\n        -\u003ewith($validation-\u003egetErrors(), 400);\n}        \n```\n\nPlease refer to the docs from [Rakit Validation](https://github.com/rakit/validation) for more information on available rules and possibilities.\n\n## Advanced Topics\n\n### PSR-4 and Autoloading\n\nBefore you proceed with complex examples, be sure that your composer.json contains an \"autoload\" section like the following:\n\n```bash\n{\n    \"require\": {\n        \"gotzmann/comet\": \"^1.0\",\n    },\n    \"autoload\": {\n        \"psr-4\": { \"App\\\\\": \"src/\" }\n    }\n}\n```    \n\nIf not, you should add the section mentioned above and update all vendor packages and autoload logic by issuing the \nfollowing command:\n\n```bash\n$ composer update\n```    \n\n### Controllers\n\nCreate src/Controllers/SimpleController.php:\n\n```php\n\u003c?php\ndeclare(strict_types=1);\n\nnamespace App\\Controllers;\n\nuse Comet\\Request;\nuse Comet\\Response;\n\nclass SimpleController\n{    \n    private static $counter = 0;\n\n    public function getCounter(Request $request, Response $response, $args)\n    {\n        $response-\u003egetBody()-\u003ewrite(self::$counter);  \n        return $response-\u003ewithStatus(200);\n    }\n\n    public function setCounter(Request $request, Response $response, $args)    \n    {        \n        $body = (string) $request-\u003egetBody();\n        $json = json_decode($body);\n        if (!$json) {\n            return $response-\u003ewithStatus(500);\n        }  \n        self::$counter = $json-\u003ecounter;\n        return $response;        \n    }\n}  \n```    \n\nThen create Comet server app.php in the project root folder:\n\n```php\n\u003c?php\ndeclare(strict_types=1);\n\nuse Comet\\Comet;\nuse App\\Controllers\\SimpleController;\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\n$app = new Comet([\n    'host' =\u003e 'localhost',\n    'port' =\u003e 8080,    \n]);\n\n$app-\u003esetBasePath(\"/api/v1\"); \n\n$app-\u003eget('/counter',\n    'App\\Controllers\\SimpleController:getCounter');\n\n$app-\u003epost('/counter',    \n    'App\\Controllers\\SimpleController:setCounter');\n\n$app-\u003erun();\n```\n\nNow you are ready to get a counter value via an API GET endpoint. And pay attention to the `/api/v1` prefix of the URL:\n\nGET http://localhost:8080/api/v1/counter\n\nYou can change the counter sending a JSON request via a POST method:\n\nPOST http://localhost:8080/api/v1/counter with body { \"counter\": 100 } and 'application/json' header.\n\nAny call with a malformed body will be replied with an HTTP 500 status code, as defined in the controller.\n\n## Deployment\n\n### Debugging and Logging\n\nComet allows you to debug application by showing errors and warnings on the screen console. When you move a service to \nproduction it's better to use log files instead. The code snippet below shows you how to enable on the screen debugging \nand  logging with the popular Monolog library:\n\n```php\n\u003c?php\ndeclare(strict_types=1);\n\nuse Comet\\Comet;\nuse Monolog\\Logger;\nuse Monolog\\Handler\\StreamHandler;\nuse Monolog\\Formatter\\LineFormatter;\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\n$formatter = new LineFormatter(\"\\n%datetime% \u003e\u003e %channel%:%level_name% \u003e\u003e %message%\", \"Y-m-d H:i:s\");\n$stream = new StreamHandler(__DIR__ . '/log/app.log', Logger::INFO);\n$stream-\u003esetFormatter($formatter);\n$logger = new Logger('app');\n$logger-\u003epushHandler($stream);\n\n$app = new Comet([\n    'debug' =\u003e true,\n    'logger' =\u003e $logger,\n]);\n\n$app-\u003erun();\n```\n\n### Docker\n\nPlease see [Dockerfile](Dockerfile) in this repo as a starting point for creating your own app images and containers.\n\n### Nginx\n\nIf you would like to use Nginx as a reverse proxy or load balancer for your Comet app, insert the following lines into \nthe nginx.conf:\n\n```php\nhttp {\n \n    upstream app {\n        server http://path.to.your.app:port;\n    }\n  \n    server {\n        listen 80;\n         location / {\n            proxy_pass         http://app;\n            proxy_redirect     off;\n        }\n    }\n}    \n```\n\n## FAQ\n\n**Got error `stream_socket_server(): unable to connect to tcp://0.0.0.0:80 (Permission denied)` trying to start Comet \nunder my Ubuntu?**\n\nComet needs to be run as root in order to bind to port 80 or any other port lower than 1000. So either start with sudo \nor just use a port like 8080.","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotzmann%2Fcomet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgotzmann%2Fcomet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgotzmann%2Fcomet/lists"}