bobthecow/psysh

psysh seems to break slim framework

Closed this issue · 2 comments

Hi,
i'm new to psysh, so i'm not sure if it's me or a real bug.
I have a hello world slim application like this:

<?php
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;

require 'vendor/autoload.php';

$app = new \Slim\App();
$app->get('/hello/{name}', function (
    Request $request,
    Response $response,
    array $args
) {
    $name = $args['name'];
    $response->getBody()->write("Hello, $name");

    return $response;
});
$app->run();

which works fine.

debugging in the route-part seems to work fine:

<?php
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;

require 'vendor/autoload.php';

$app = new \Slim\App();
$app->get('/hello/{name}', function (
    Request $request,
    Response $response,
    array $args
) {
    $name = $args['name'];
    eval(\Psy\sh());
    $response->getBody()->write("Hello, $name");

    return $response;
});
$app->run();

the shell works as intended, but leaving the shell with quit results in the following exception:

Psy Shell v0.9.9 (PHP 7.0.33-0+deb9u3 — cli-server) by Justin Hileman

From index.php:14:

    12| ) {
    13|     $name = $args['name'];
  > 14|     eval(\Psy\sh());
    15|     $response->getBody()->write("Hello, $name");
    16| 

>>> q
Exit:  Goodbye
[Wed Jul 10 15:14:57 2019] Slim Application Error:
Type: RuntimeException
Message: Could not write to stream
File: aapt/vendor/slim/slim/Slim/Http/Stream.php
Line: 407
Trace: #0 aapt/index.php(15): Slim\Http\Stream->write('Hello, ztTt')
#1 [internal function]: Closure->{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#2 aapt/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(41): call_user_func(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#3 aapt/vendor/slim/slim/Slim/Route.php(356): Slim\Handlers\Strategies\RequestResponse->__invoke(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array)
#4 aapt/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\Route->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#5 aapt/vendor/slim/slim/Slim/Route.php(334): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#6 aapt/vendor/slim/slim/Slim/App.php(515): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Http\Response))
#7 aapt/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(117): Slim\App->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response))
#8 aapt/vendor/slim/slim/Slim/App.php(405): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response))
#9 aapt/vendor/slim/slim/Slim/App.php(313): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response))
#10 aapt/index.php(19): Slim\App->run()
#11 {main}
View in rendered output by enabling the "displayErrorDetails" setting.

Am i doing something wrong here or is this in fakt a bug?

Some things get weird with forks. Try disabling then with ’usePcntl' => false in your psysh config?

Yes, that solved it.
Thanks!