Giter Site home page Giter Site logo

PSR7 for HTTP Protocol about workerman HOT 12 OPEN

walkor avatar walkor commented on May 14, 2024
PSR7 for HTTP Protocol

from workerman.

Comments (12)

walkor avatar walkor commented on May 14, 2024 13

Here is example for workerman with PSR 7.

install

composer require workerman/psr7 ~1.4.4

example

<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
use Workerman\Protocols\Http;
use Workerman\Psr7\Response;
use Workerman\Psr7\ServerRequest;

$worker = new Worker('http://0.0.0.0:12345');
Http::requestClass(Workerman\Psr7\ServerRequest::class);
$worker->onMessage = function($connection, ServerRequest $request)
{
    $response = new Response(200, [], 'hello world');
    $connection->send($response);
};

Worker::runAll();

from workerman.

gotzmann avatar gotzmann commented on May 14, 2024 7

If anyone interested, I've used Workerman as the platform for building perfromant PSR7 framework here:

https://github.com/gotzmann/comet

There transparent transformation between Workerman internal Request and Response classes and PSR-7 compliant ones.

from workerman.

walkor avatar walkor commented on May 14, 2024 3

Thank you for your post @Arul- .
But I want to make workerman as simple as possible. I think it's a better choice to build a new PSR7 project and use composer to install it.

from workerman.

Arul- avatar Arul- commented on May 14, 2024 2

Take a look at my implementation at https://github.com/Arul-/reactive-restler/blob/dev/interop/Workerman/Psr7.php

The only dependency it has with the rest of my framework is

$class = ClassName::get(ServerRequestInterface::class);

It can easily be changed by hardcoding the PSR Request class

I can make a pull request here if you like

from workerman.

dominikzogg avatar dominikzogg commented on May 14, 2024 2

A request handler adapter for workerman, using PSR-7, PSR-15 and PSR-17. Which can be used with every framework which is PSR-7 based.

https://github.com/chubbyphp/chubbyphp-workerman-request-handler

from workerman.

walkor avatar walkor commented on May 14, 2024

Sorry. There is no plan at present.
: - (

from workerman.

praswicaksono avatar praswicaksono commented on May 14, 2024

Well I can help if you man but it require intensive communication. Where I can reach you for more talk about this? any IM maybe

from workerman.

praswicaksono avatar praswicaksono commented on May 14, 2024

either gitter or IRC is fine with me since those tools already used by most opensource project also it can attract foreign developer to contribute.

from workerman.

walkor avatar walkor commented on May 14, 2024

https://gitter.im is ok.
I've joined Atriedes and joostshao in the chat.

from workerman.

Arul- avatar Arul- commented on May 14, 2024

Understood!

from workerman.

tourze avatar tourze commented on May 14, 2024

Here is example for workerman with PSR 7.

install

composer require workerman/psr7 ~1.4.4

example

<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
use Workerman\Protocols\Http;
use Workerman\Psr7\Response;
use Workerman\Psr7\ServerRequest;

$worker = new Worker('http://0.0.0.0:12345');
Http::requestClass(Workerman\Psr7\ServerRequest::class);
$worker->onMessage = function($connection, ServerRequest $request)
{
    $response = new Response(200, [], 'hello world');
    $connection->send($response);
};

Worker::runAll();

In workerman 4.x, $connection->send($response); is not work perfectly.
It is better to use $connection->send(\Workerman\Psr7\response_to_string($response), true);

from workerman.

jhdxr avatar jhdxr commented on May 14, 2024

As workerman is now introducing/enhancing the HTTP class with its friends. Is there any plan to make those class PSR-7 compatible?

from workerman.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.