Skip to content
View orolyn's full-sized avatar

Block or report orolyn

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 100 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
orolyn/README.md

Orolyn PHP Library

A fiber based asynchronous tooling library for server development.

Documentation

Documentation is provided at readthedocs.org

What is it

This library provides general purpose tools for server development. The primary goal of this library is to enable development with a familiar synchronous pattern while utilizing fibers to allow for multithreading-like operations.

    use Orolyn\Concurrency\Application;
    use Orolyn\Concurrency\TaskScheduler;
    use Orolyn\Net\Http\FailedHttpRequestException;
    use Orolyn\Net\Http\HttpRequestContext;
    use Orolyn\Net\Http\HttpServer;
    use Orolyn\Net\Http\WebSocket\InvalidWebSocketContextException;
    use Orolyn\Net\Http\WebSocket\WebSocket;
    use Orolyn\Net\Http\WebSocket\WebSocketClosedException;
    use Orolyn\Net\IPAddress;
    use Orolyn\Net\IPEndPoint;
    use function Orolyn\Lang\Async;

    class ApplicationServer extends Application
    {
        public function main(): void
        {
            $httpServer = new HttpServer();
            $httpServer->listen(new IPEndPoint(IPAddress::parse('0.0.0.0'), 9999));

            while ($httpServer->isListening()) {
                try {
                    $context = $httpServer->accept();
                    Async(fn() => $this->handleRequest($context));
                } catch (FailedHttpRequestException $exception) {
                    /* Log error */
                }
            }
        }

        private function handleRequest(HttpRequestContext $context): void
        {
            try {
                $websocket = WebSocket::create($context);
            } catch (InvalidWebSocketContextException $exception) {
                /* Log error */
                return;
            }

            try {
                $websocket->send('Hi!!!!!');
                $data = $websocket->receive()->getData();

                if ('okthxbye' === $data) {
                    $websocket->send('Oh..');
                    $websocket->close();

                    return;
                }

                /* Lets get to work */

            } catch (WebSocketClosedException $exception) {
                return;
            }
        }
    }

    TaskScheduler::run(new ApplicationServer());

Popular repositories Loading

  1. orolyn orolyn Public

    PHP 1

  2. GPIO-Practice-1 GPIO-Practice-1 Public

    It's only practice, no singularities here.

    Python

  3. php-eio-stubs php-eio-stubs Public

    Stubs for Pecl-EIO

    PHP

  4. chat-room-demo chat-room-demo Public

    Practice and demo application for Websocket servers.

    PHP

  5. tbpc tbpc Public

    PHP

  6. template-based-generics template-based-generics Public

    PHP