workerman icon indicating copy to clipboard operation
workerman copied to clipboard

PSR7 for HTTP Protocol

Open praswicaksono opened this issue 8 years ago • 12 comments

Is there any plan to implement PSR 7 for HTTP Protocol?

praswicaksono avatar Dec 29 '15 03:12 praswicaksono

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

walkor avatar Dec 29 '15 13:12 walkor

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

praswicaksono avatar Dec 29 '15 16:12 praswicaksono

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.

praswicaksono avatar Dec 31 '15 03:12 praswicaksono

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

walkor avatar Dec 31 '15 05:12 walkor

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

Arul- avatar Feb 12 '19 13:02 Arul-

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.

walkor avatar Feb 14 '19 06:02 walkor

Understood!

Arul- avatar Feb 14 '19 07:02 Arul-

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.

gotzmann avatar Jun 18 '20 14:06 gotzmann

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

dominikzogg avatar Aug 08 '20 11:08 dominikzogg

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();

walkor avatar Sep 01 '20 09:09 walkor

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);

tourze avatar Mar 15 '22 03:03 tourze

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

jhdxr avatar Apr 13 '23 21:04 jhdxr