laravel / octane

Supercharge your Laravel application's performance.
https://laravel.com/docs/octane
MIT License
3.78k stars 296 forks source link

phpinfo() output missing markup when called from controller/route method #414

Closed carestad closed 3 years ago

carestad commented 3 years ago

Description:

phpinfo() output is missing markup whtn called from a controller method or route closure. php_sapi_name() is also cli where for artisan:serve it would be cli-server. This happens with both Swoole and Roadrunner.

Steps To Reproduce:

Example route:

Route::get('/phpinfo', function() {
    phpinfo();
});

When "hosting" with artisan serve, navigating to /phpinfo will show a colourful output. CTRL+U (view source) reveals a lot of markup and styling involved.

When hosting with artisan octane:start, the output is stripped of markup and is the same as when calling phpinfo() from CLI, like tinker or a simple script run from the command line. Output of php_sapi_name() also says cli at this point, which would explain it.

Simple workaround for now to at least get some structure to the page is to rewrite route like this:

Route::get('/phpinfo', function() {
    phpinfo();
    return response('')->withHeaders(['content-type' => 'text/plain']);
});
nunomaduro commented 3 years ago

Unfortunately, because Octane is started from the "CLI", there is not real way of mutating the SAPI PHP module. So all php core functions, based on that module, including phpinfo, will work a little bit differently.

manusiakemos commented 5 months ago

for me it works with

ob_start();
phpinfo();
$phpinfo = ob_get_clean();

return response($phpinfo, 200)
    ->header('Content-Type', 'text/html');