{"id":18369754,"url":"https://github.com/dazzle-php/loop","last_synced_at":"2025-04-06T18:32:27.932Z","repository":{"id":56963775,"uuid":"95145128","full_name":"dazzle-php/loop","owner":"dazzle-php","description":"Dazzle Async I/O Event Loop","archived":false,"fork":false,"pushed_at":"2017-08-20T18:18:12.000Z","size":97,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-20T20:17:35.525Z","etag":null,"topics":["async","dazzle","event","event-loop","loop","php","php-lib","php7","queue","select","stream-select"],"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/dazzle-php.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-22T18:30:41.000Z","updated_at":"2024-12-16T16:13:43.000Z","dependencies_parsed_at":"2022-08-21T10:20:21.262Z","dependency_job_id":null,"html_url":"https://github.com/dazzle-php/loop","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dazzle-php%2Floop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dazzle-php%2Floop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dazzle-php%2Floop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dazzle-php%2Floop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dazzle-php","download_url":"https://codeload.github.com/dazzle-php/loop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247531264,"owners_count":20953929,"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":["async","dazzle","event","event-loop","loop","php","php-lib","php7","queue","select","stream-select"],"created_at":"2024-11-05T23:31:36.063Z","updated_at":"2025-04-06T18:32:24.638Z","avatar_url":"https://github.com/dazzle-php.png","language":"PHP","readme":"# Dazzle Async I/O Event Loop\n\n[![Build Status](https://travis-ci.org/dazzle-php/loop.svg)](https://travis-ci.org/dazzle-php/loop)\n[![Code Coverage](https://scrutinizer-ci.com/g/dazzle-php/loop/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/dazzle-php/loop/?branch=master)\n[![Code Quality](https://scrutinizer-ci.com/g/dazzle-php/loop/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/dazzle-php/loop/?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/dazzle-php/loop/v/stable)](https://packagist.org/packages/dazzle-php/loop) \n[![Latest Unstable Version](https://poser.pugx.org/dazzle-php/loop/v/unstable)](https://packagist.org/packages/dazzle-php/loop) \n[![License](https://poser.pugx.org/dazzle-php/loop/license)](https://packagist.org/packages/dazzle-php/loop/license)\n\n\u003e **Note:** This repository is part of [Dazzle Project](https://github.com/dazzle-php/dazzle) - the next-gen library for PHP. The project's purpose is to provide PHP developers with a set of complete tools to build functional async applications. Please, make sure you read the attached README carefully and it is guaranteed you will be surprised how easy to use and powerful it is. In the meantime, you might want to check out the rest of our async libraries in [Dazzle repository](https://github.com/dazzle-php) for the full extent of Dazzle experience.\n\n\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/dazzle-php/dazzle/master/media/dazzle-x125.png\" /\u003e\n\u003c/p\u003e\n\n## Description\n\nDazzle Loop is a component that provides abstraction layer for writing asynchronous code in PHP on single thread or process with usage of single or multiple loops.\n\n## Feature Highlights\n\nDazzle Loop features:\n\n* Interface for writing asynchronous code on single Thread or Process,\n* File descriptor polling,\n* One-time and periodic timers,\n* Deferred execution of callbacks,\n* Support for StreamSelect -based loops,\n* ~~Support for LibEvent -based loops~~,\n* ~~Support for LibEv -based loops~~,\n* ~~Support for ExtEvent -based loops~~,\n* Support for combining multiple loops and managing them from one wrapper,\n* Support for switching between multiple execution flows,\n* ReactPHP Event-Loop adapters,\n* ReactPHP compatibility,\n* ...and more.\n\n## Provided Example(s)\n\n### Quickstart\n\nThis example shows implementation of non-blocking clock using loop:\n\n```php\n$loop = new Loop();\n\n$loop-\u003eaddPeriodicTimer(1, function() {\n    printf(\"\\rCurrent clock: %s\", date('Y-m-d H:i:s'));\n});\n\n$loop-\u003estart();\n```\n\n### Additional\n\nAdditional examples can be found in [example](https://github.com/dazzle-php/loop/tree/master/example) directory. Below is the list of provided examples as a reference and preferred consumption order:\n\n- [Quickstart](https://github.com/dazzle-php/loop/blob/master/example/loop_quickstart.php)\n- [Using Loop start/stop events](https://github.com/dazzle-php/loop/blob/master/example/loop_using_events.php)\n- [Scheduling simple timers](https://github.com/dazzle-php/loop/blob/master/example/loop_using_simple_timers.php)\n- [Scheduling periodic timers](https://github.com/dazzle-php/loop/blob/master/example/loop_using_periodic_timers.php)\n- [Scheduling periodic timers with manual control](https://github.com/dazzle-php/loop/blob/master/example/loop_using_periodic_timers_controls.php)\n- [Cancelling timers](https://github.com/dazzle-php/loop/blob/master/example/loop_cancelling_timers.php)\n- [Cancelling timers alternatively](https://github.com/dazzle-php/loop/blob/master/example/loop_cancelling_timers_alternative.php)\n- [Queueing tick listeners](https://github.com/dazzle-php/loop/blob/master/example/loop_listening_on_ticks.php)\n- [Queueing tick listeners to begin/end of queue](https://github.com/dazzle-php/loop/blob/master/example/loop_listening_on_ticks_all.php)\n- [Using streams asynchronously - pt 1](https://github.com/dazzle-php/loop/blob/master/example/loop_io_stream_source.php)\n- [Using streams asynchronously - pt 2](https://github.com/dazzle-php/loop/blob/master/example/loop_io_stream_pipe.php)\n- [__Advanced:__  Implementing simple HTTP server](https://github.com/dazzle-php/loop/blob/master/example/loop_http_server.php)\n\nIf any of the above examples has left you confused, please take a look in the [tests](https://github.com/dazzle-php/loop/tree/master/test) directory as well.\n\n## Comparison\n\nThis section contains Dazzle vs React comparison many users requested. If you are wondering why this section has been created, see the [author's note](https://github.com/dazzle-php/dazzle/blob/master/NOTE.md).\n\n#### Performance\n\n\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/dazzle-php/loop/master/media/graph-perf-cpu.png\" /\u003e\n\u003c/p\u003e\n\nThe detailed information about this benchmark can be found in [benchmark-on.php](https://github.com/dazzle-php/loop/blob/master/example-bench/benchmark.php) and [benchmark-react.php](https://github.com/dazzle-php/loop/blob/master/example-bench/benchmark-react.php) files.\n\n#### Memory Allocation Efficiency\n\n\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/dazzle-php/loop/master/media/graph-perf-mem.png\" /\u003e\n\u003c/p\u003e\n\nThe detailed information about this benchmark can be found in [benchmark-once.php](https://github.com/dazzle-php/loop/blob/master/example-bench/benchmark.php) and [benchmark-react.php](https://github.com/dazzle-php/loop/blob/master/example-bench/benchmark-react.php) files.\n\n#### Details\n\n| Detail | Dazzle Event | React-equivalent |\n| :--- | :---: | :---: |\n| Active support | X | ? |\n| Provided well-formed documentation | X | X |\n| Provided well-formed set of tests with at least 80% coverage and API examples | X | X |\n| Support for executing event ticks | X | X |\n| Support for before and after event ticks listeners | X | X |\n| Support for timers | X | X |\n| Support for periodic timers | X | X | \n| Asynchronous writing of streams | X | X |\n| Asynchronous reading of streams | X | X |\n| Cancelling timers | X | X |\n| Implemented stream model | X | X |\n| Implemented lib-event model | WIP | X |\n| Implemented lib-ev model | WIP | X |\n| Implemented ext-event model | WIP | X |\n| Support for state change events | X | |\n| Support for flow controls | X | |\n| Support for multiple flows and switching between active ones | X | |\n\n## Requirements\n\nLoop requires:\n\n* PHP-5.6 or PHP-7.0+,\n* UNIX or Windows OS.\n\n## Installation\n\nTo install this library make sure you have [composer](https://getcomposer.org/) installed, then run following command:\n\n```\n$\u003e composer require dazzle-php/loop\n```\n\n## Tests\n\nTests can be run via:\n\n```\n$\u003e vendor/bin/phpunit -d memory_limit=1024M\n```\n\n## Versioning\n\nVersioning of Dazzle libraries is described in versioning section of [Dazzle Project](https://github.com/dazzle-php/dazzle) index repository. Please, refer there for detailed information on the subject.\n\n## Contributing\n\nThank you for considering contributing to this repository! \n\n- The contribution guide can be found in the [contribution tips](https://github.com/dazzle-php/loop/blob/master/CONTRIBUTING.md). \n- Open tickets can be found in [issues section](https://github.com/dazzle-php/loop/issues). \n- Current contributors are listed in [graphs section](https://github.com/dazzle-php/loop/graphs/contributors)\n- To contact the author(s) see the information attached in [composer.json](https://github.com/dazzle-php/loop/blob/master/composer.json) file.\n\n## License\n\nDazzle Loop is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).\n\n\u003chr\u003e\n\u003cp align=\"center\"\u003e\n\u003ci\u003e\"Everything is possible. The impossible just takes longer.\"\u003c/i\u003e ― Dan Brown\n\u003c/p\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdazzle-php%2Floop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdazzle-php%2Floop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdazzle-php%2Floop/lists"}