Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Built-in support for fibers on PHP 8.1+ with stable reactphp/async #168

Merged
merged 1 commit into from
Jul 14, 2022

Conversation

clue
Copy link
Owner

@clue clue commented Jul 14, 2022

This changeset adds built-in support for fibers on PHP 8.1+ with stable reactphp/async v4. The fiber compatibility mode for PHP < 8.1 now also uses stable reactphp/async v3. This makes building and consuming async APIs easier than ever before.

$app->get('/book/{isbn}', function (Psr\Http\Message\ServerRequestInterface $request) use ($db) {
    $isbn = $request->getAttribute('isbn');
    $result = await($db->query(
        'SELECT title FROM book WHERE isbn = ?',
        [$isbn]
    ));

    assert($result instanceof React\MySQL\QueryResult);
    $data = $result->resultRows[0]['title'];

    return React\Http\Message\Response::plaintext(
        $data
    );
});

Most notably, this changeset adds required dependencies to make sure the fiber API works across all installations. It does not otherwise affect existing installations. All changes have been performed upstream in the reactphp/async component, so we can take advantage of this finally now that it is available as a stable release via https://github.com/reactphp/async/releases/tag/v4.0.0.

Builds on top of #117 and #128

@clue clue added the new feature New feature or request label Jul 14, 2022
@clue clue merged commit de56bde into clue:main Jul 14, 2022
@clue clue deleted the async-fibers branch July 14, 2022 15:29
@SimonFrings SimonFrings added this to the v0.10.0 milestone Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants