-
Notifications
You must be signed in to change notification settings - Fork 3
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
phpixie inside reactphp #1
Comments
Sure, but I am on vacation atm, so I dont have much time for that. Ill post
|
Actually I just gave it a go, the important part is converting ReactPHP requests to PSR-7: reactphp/http#28 As soon as they have PSR-7 support it should be a one liner, but for now it will take some tinkering to convert them manually. The flow is pretty much this: require_once(__DIR__.'/../vendor/autoload.php');
$pixie = new Project\Framework();
$pixie->registerDebugHandlers();
$app = function ($request, $response) use($pixie) {
$psr7ServerRequest = convertRequestToPsr7($request);
$psr7Response = $pixie->processHttpServerRequest($psr7ServerRequest);
convertPsr7Response($response);
};
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket, $loop);
$http->on('request', $app);
echo "Server running at http://127.0.0.1:1337\n";
$socket->listen(1337);
$loop->run(); I could not find anything that converts React requests to psr7 requests but there must be something available. if not, you can use this to build one (just pass relevant parameters extracted from react request): $http = $pixie->builder->components()->http();
$psr7ServerRequest = $http->messages()->serverRequest(...); https://github.com/PHPixie/HTTP/blob/master/src/PHPixie/HTTP/Messages.php#L27 |
Do you have some guides converting to reactphp response? 发送自我的 BlackBerry 10 智能手机。 Actually I just gave it a go, the important part is converting ReactPHP requests to PSR-7: reactphp/http#28 As soon as they have PSR-7 support it should be a one liner, but for now it will take some tinkering to convert them manually. The flow is pretty much this: require_once(__DIR__.'/../vendor/autoload.php');
$pixie = new Project\Framework();
$pixie->registerDebugHandlers();
$app = function ($request, $response) use($pixie) {
$psr7ServerRequest = convertRequestToPsr7($request);
$psr7Response = $pixie->processHttpServerRequest($psr7ServerRequest);
convertPsr7Response($response);
};
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket, $loop);
$http->on('request', $app);
echo "Server running at http://127.0.0.1:1337\n";
$socket->listen(1337);
$loop->run(); I could not find anything that converts React requests to psr7 requests but there must be something available. if not, you can use this to build one (just pass relevant parameters extracted from react request): $http = $pixie->builder->components()->http();
$psr7ServerRequest = $http->messages()->serverRequest(...); https://github.com/PHPixie/HTTP/blob/master/src/PHPixie/HTTP/Messages.php#L27 Reply to this email directly or view it on GitHub: |
<?php
require_once('vendor/autoload.php');
$host = 'localhost';
$port = 1337;
$framework = new Project\Framework();
$framework->registerDebugHandlers(false, false);
$app = function ($request, $response) use ($framework, $host, $port) {
$http = $framework->builder()->components()->http();
$uri = $http->messages()->uri('http://'.$host.':'.$port.$request->getPath());
$serverRequest = $http->messages()->serverRequest(
$request->getHttpVersion(),
$request->getHeaders(),
'',
$request->getMethod(),
$uri,
array(),
$request->getQuery(),
array(),
array(),
array()
);
$frameworkResponse = $framework->processHttpServerRequest($serverRequest);
$response->writeHead(
$frameworkResponse->getStatusCode(),
$frameworkResponse->getHeaders()
);
$response->end(
$frameworkResponse->getBody()
);
};
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket);
$http->on('request', $app);
$socket->listen($port);
$loop->run(); Here you go =) |
Real guru! 发送自我的 BlackBerry 10 智能手机。 <?php
require_once('vendor/autoload.php');
$host = 'localhost';
$port = 1337;
$framework = new Project\Framework();
$framework->registerDebugHandlers(false, false);
$app = function ($request, $response) use ($framework, $host, $port) {
$http = $framework->builder()->components()->http();
$uri = $http->messages()->uri('http://'.$host.':'.$port.$request->getPath());
$serverRequest = $http->messages()->serverRequest(
$request->getHttpVersion(),
$request->getHeaders(),
'',
$request->getMethod(),
$uri,
array(),
$request->getQuery(),
array(),
array(),
array()
);
$frameworkResponse = $framework->processHttpServerRequest($serverRequest);
$response->writeHead(
$frameworkResponse->getStatusCode(),
$frameworkResponse->getHeaders()
);
$response->end(
$frameworkResponse->getBody()
);
};
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket);
$http->on('request', $app);
$socket->listen($port);
$loop->run(); Here you go =) Reply to this email directly or view it on GitHub: |
Thanks =))))))))))) Although do keep in mind ReactPHP has a few limitations, like not parsing $_POST data by default, so I did not include it in this example. If you'll need anything specific just ask =) |
could you please write some code sample running phpixie inside reactphp
The text was updated successfully, but these errors were encountered: