-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revolt is the result of combining years of experience of amphp's and ReactPHP's event loop implementations. Co-authored-by: Aaron Piotrowski <[email protected]> Co-authored-by: Cees-Jan Kiewiet <[email protected]> Co-authored-by: Christian Lück <[email protected]> Co-authored-by: Niklas Keller <[email protected]>
- Loading branch information
Showing
69 changed files
with
7,109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
charset = utf-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.github export-ignore | ||
docs export-ignore | ||
examples export-ignore | ||
stubs export-ignore | ||
test export-ignore | ||
tools export-ignore | ||
.editorconfig export-ignore | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
.php-cs-fixer.* export-ignore | ||
.phpunit.* export-ignore | ||
CHANGELOG.md export-ignore | ||
CONTRIBUTING.md export-ignore | ||
phpunit.xml.dist export-ignore | ||
psalm.examples.xml export-ignore | ||
psalm.xml export-ignore | ||
README.md export-ignore |
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @revoltphp/event-loop-maintainers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Continuous Integration | ||
|
||
on: | ||
- push | ||
- pull_request | ||
|
||
jobs: | ||
tests: | ||
timeout-minutes: 5 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- operating-system: 'ubuntu-latest' | ||
php-version: '8.0' | ||
composer-flags: '--ignore-platform-req=php' | ||
|
||
name: PHP ${{ matrix.php-version }} ${{ matrix.job-description }} | ||
|
||
runs-on: ${{ matrix.operating-system }} | ||
|
||
steps: | ||
- name: Set git to use LF | ||
run: | | ||
git config --global core.autocrlf false | ||
git config --global core.eol lf | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-version }} | ||
extensions: fiber-amphp/ext-fiber@master | ||
|
||
- name: Get Composer cache directory | ||
id: composer-cache | ||
run: echo "::set-output name=dir::$(composer config cache-dir)" | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-${{ matrix.composer-flags }} | ||
restore-keys: | | ||
composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}- | ||
composer-${{ runner.os }}-${{ matrix.php-version }}- | ||
composer-${{ runner.os }}- | ||
composer- | ||
- name: Install dependencies | ||
uses: nick-invision/retry@v2 | ||
with: | ||
timeout_minutes: 5 | ||
max_attempts: 5 | ||
retry_wait_seconds: 30 | ||
command: | | ||
composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }} | ||
composer info -D | ||
- name: Run tests | ||
run: vendor/bin/phpunit ${{ matrix.phpunit-flags }} | ||
|
||
- name: Run Psalm | ||
run: vendor/bin/psalm.phar --show-info=true | ||
|
||
- name: Run style fixer | ||
env: | ||
PHP_CS_FIXER_IGNORE_ENV: 1 | ||
run: | | ||
composer install --optimize-autoloader --no-interaction --no-progress --working-dir=tools/php-cs-fixer | ||
tools/php-cs-fixer/vendor/bin/php-cs-fixer --diff --dry-run -v fix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
build | ||
composer.lock | ||
composer.phar | ||
coverage | ||
phpunit.xml | ||
vendor | ||
*.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Revolt; | ||
|
||
use PhpCsFixer\Config as PhpCsFixerConfig; | ||
|
||
final class Config extends PhpCsFixerConfig | ||
{ | ||
private string $src; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct('Revolt'); | ||
|
||
$this->setRiskyAllowed(true); | ||
$this->setLineEnding("\n"); | ||
|
||
$this->src = __DIR__ . '/src'; | ||
} | ||
|
||
public function getRules(): array | ||
{ | ||
return [ | ||
"@PSR1" => true, | ||
"@PSR2" => true, | ||
"@PSR12" => true, | ||
"braces" => [ | ||
"allow_single_line_closure" => true, | ||
], | ||
"array_syntax" => ["syntax" => "short"], | ||
"cast_spaces" => true, | ||
"combine_consecutive_unsets" => true, | ||
"function_to_constant" => true, | ||
"native_function_invocation" => [ | ||
'include' => [ | ||
'@internal', | ||
'pcntl_async_signals', | ||
'pcntl_signal_dispatch', | ||
'pcntl_signal', | ||
'posix_kill', | ||
'uv_loop_new', | ||
'uv_poll_start', | ||
'uv_poll_stop', | ||
'uv_now', | ||
'uv_run', | ||
'uv_poll_init_socket', | ||
'uv_timer_init', | ||
'uv_timer_start', | ||
'uv_timer_stop', | ||
'uv_signal_init', | ||
'uv_signal_start', | ||
'uv_signal_stop', | ||
'uv_update_time', | ||
'uv_is_active', | ||
], | ||
], | ||
"multiline_whitespace_before_semicolons" => true, | ||
"no_unused_imports" => true, | ||
"no_useless_else" => true, | ||
"no_useless_return" => true, | ||
"no_whitespace_before_comma_in_array" => true, | ||
"no_whitespace_in_blank_line" => true, | ||
"non_printable_character" => true, | ||
"normalize_index_brace" => true, | ||
"ordered_imports" => ['imports_order' => ['class', 'const', 'function']], | ||
"php_unit_construct" => true, | ||
"php_unit_dedicate_assert" => true, | ||
"php_unit_fqcn_annotation" => true, | ||
"phpdoc_summary" => true, | ||
"phpdoc_types" => true, | ||
"psr_autoloading" => ['dir' => $this->src], | ||
"return_type_declaration" => ["space_before" => "none"], | ||
"short_scalar_cast" => true, | ||
"single_blank_line_before_namespace" => true, | ||
"line_ending" => true, | ||
]; | ||
} | ||
} | ||
|
||
$config = new Config; | ||
$config->getFinder() | ||
->in(__DIR__ . '/examples') | ||
->in(__DIR__ . '/src') | ||
->in(__DIR__ . '/test'); | ||
|
||
$config->setCacheFile(__DIR__ . '/.php-cs-fixer.cache'); | ||
|
||
return $config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
## TBD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
## Submitting useful bug reports | ||
|
||
Please search existing issues first to make sure this is not a duplicate. | ||
Every issue report has a cost for the developers required to field it; be | ||
respectful of others' time and ensure your report isn't spurious prior to | ||
submission. Please adhere to [sound bug reporting principles](http://www.chiark.greenend.org.uk/~sgtatham/bugs.html). | ||
|
||
## Development ideology | ||
|
||
Truths which we believe to be self-evident: | ||
|
||
- **It's an asynchronous world.** Be wary of anything that undermines | ||
async principles. | ||
|
||
- **The answer is not more options.** If you feel compelled to expose | ||
new preferences to the user it's very possible you've made a wrong | ||
turn somewhere. | ||
|
||
- **There are no power users.** The idea that some users "understand" | ||
concepts better than others has proven to be, for the most part, false. | ||
If anything, "power users" are more dangerous than the rest, and we | ||
should avoid exposing dangerous functionality to them. | ||
|
||
## Code style | ||
|
||
The project adheres to the [PSR-2 style guide](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md | ||
). | ||
|
||
To apply code standards you can run `php-cs-fixer` with following composer command: | ||
|
||
```bash | ||
composer code-style | ||
``` | ||
|
||
## Running the tests | ||
|
||
Run the test suite from root directory: | ||
|
||
```bash | ||
composer test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2021 Revolt (Aaron Piotrowski, Cees-Jan Kiewiet, Christian Lück, Niklas Keller, and contributors) | ||
Copyright (c) 2015-2021 amphp (Daniel Lowrey, Aaron Piotrowski, Niklas Keller, Bob Weinand, and contributors) | ||
Copyright (c) 2012-2021 ReactPHP (Christian Lück, Cees-Jan Kiewiet, Jan Sorgalla, Chris Boden, Igor Wiedler, and contributors) | ||
Copyright (c) 2016 PHP Asynchronous Interoperability Group | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Revolt <a href="blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" valign="middle"></a> | ||
|
||
Revolt is a rock-solid event loop for concurrent PHP applications. | ||
|
||
## Motivation | ||
|
||
Traditionally, PHP has a synchronous execution flow, doing one thing at a time. | ||
If you query a database, you send the query and wait for the response from the database server in a blocking manner. | ||
Once you have the response, you can start doing the next thing. | ||
|
||
Instead of sitting there and doing nothing while waiting, we could already send the next database query, or do an HTTP call to an API. | ||
Making use of the time we usually spend on waiting for I/O can speed up the total execution time. | ||
|
||
A single scheduler – also called event loop – is required to allow for [cooperative multitasking](https://en.wikipedia.org/wiki/Cooperative_multitasking), which this package provides. | ||
|
||
## Installation | ||
|
||
This package can be installed as a [Composer](https://getcomposer.org/) dependency. | ||
|
||
```bash | ||
composer require revolt/event-loop | ||
``` | ||
|
||
This installs the basic building block for building concurrent applications in PHP. | ||
|
||
## Documentation | ||
|
||
Documentation can be found in the [`./docs`](./docs) directory. | ||
|
||
## Requirements | ||
|
||
This package requires at least PHP 8.0. To take advantage of [Fibers](https://wiki.php.net/rfc/fibers), either [`ext-fiber`](https://github.com/amphp/ext-fiber) or PHP 8.1+ is required. | ||
|
||
##### Optional Extensions | ||
|
||
Extensions are only needed if your application necessitates a high numbers of concurrent socket connections, usually this limit is configured up to 1024 file descriptors. | ||
|
||
- [`ev`](https://pecl.php.net/package/ev) | ||
- [`event`](https://pecl.php.net/package/event) | ||
- [`uv`](https://github.com/amphp/ext-uv) | ||
|
||
## Examples | ||
|
||
Examples can be found in the [`./examples`](./examples) directory of this repository. | ||
|
||
## Versioning | ||
|
||
`revolt/event-loop` follows the [semver](https://semver.org/) semantic versioning specification. | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. | ||
|
||
Revolt is the result of combining years of experience of amphp's and ReactPHP's | ||
event loop implementations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"name": "revolt/event-loop", | ||
"description": "Rock-solid event loop for concurrent PHP applications.", | ||
"keywords": [ | ||
"async", | ||
"asynchronous", | ||
"concurrency", | ||
"non-blocking", | ||
"event", | ||
"event-loop" | ||
], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Aaron Piotrowski", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Cees-Jan Kiewiet", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Christian Lück", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Niklas Keller", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=8" | ||
}, | ||
"require-dev": { | ||
"ext-json": "*", | ||
"phpunit/phpunit": "^9", | ||
"jetbrains/phpstorm-stubs": "^2019.3", | ||
"psalm/phar": "^4.7" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Revolt\\": "src" | ||
}, | ||
"files": [ | ||
"src/functions.php", | ||
"src/EventLoop/Internal/functions.php" | ||
] | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Revolt\\EventLoop\\": "test" | ||
} | ||
}, | ||
"support": { | ||
"issues": "https://github.com/revoltphp/event-loop/issues" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-main": "1.x-dev" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "@php -dzend.assertions=1 -dassert.exception=1 ./vendor/bin/phpunit", | ||
"code-style": "@php tools/php-cs-fixer/vendor/bin/php-cs-fixer fix" | ||
} | ||
} |
Oops, something went wrong.