Skip to content
@phasync

phasync

phasync

The phasync framework is a new coroutine library for PHP which works without any extensions. With phasync, you can use asynchronous IO operations while writing code the way you have always done it in PHP.

Running Coroutines

Whenever you need to write code that uses coroutines, you simply use phasync::run(). You can use it in your existing codebase without changing anything else.

class SomeController {

    public function someMethod(): string {
        // Create a context for using async code
        return phasync::run(function() {
            // Write your code here
            $client = new HttpClient();

            // Another coroutine just for fun
            $result = phasync::go(function() {
                for ($i = 0; $i < 10; $i++) {
                    echo "Counting: $i\n";
                    phasync::sleep(0.5);
                }
                return $i;
            });

            // These requests run in parallel
            $request1 = $client->get("http://example.com/");
            $request2 = $client->get("http://example2.com/");

            return [
              $request1,
              $request2,
              phasync::await($result)
            ];
        });
    }

}

Popular repositories Loading

  1. phasync phasync Public

    Micro framework for ultra high performance PHP websites with non-blocking IO.

    PHP 244 10

  2. serializor serializor Public

    PHP Serializor will serialize almost anything in PHP, including closures and anonymous classes.

    PHP 19 2

  3. swerve swerve Public

    SWERVE - the PHP application server

    PHP 14 1

  4. http-client http-client Public

    An asynchronous HTTP client implementation with the standard PSR-18 interface using Fibers.

    PHP 8 1

  5. file-streamwrapper file-streamwrapper Public

    Make file IO transparently asynchronous inside phasync PHP coroutines

    PHP 5 1

  6. http-streamwrapper http-streamwrapper Public

    Make http:// and https:// requests asynchronous inside phasync coroutines

    PHP 1

Repositories

Showing 10 of 26 repositories

People

This organization has no public members. You must be a member to see who’s a part of this organization.

Top languages

Loading…

Most used topics

Loading…