symfony/symfony — Issue #2575: [Yaml] Do not use output buffering for parsing
Author: lisachenko
Created: 2011-11-07 15:20:37+00:00
State: open

I wrote FatalHandler for Symfony2 which uses internally output buffering to control the output and headers for response. Also it generates 'core.fatal' event which can be handled and html response can be returned for this page. Everything is good until cache rebuild. There is one big problem when I want to reload cache. In that case output buffering is started in my handler, then kernel tries to boot and loads configuration for YAML which also use ob_start(). The problem is that inside the output callback function call to another output control function will generate fatal error and this will lead to empty page with 200 result:

PHP Fatal error: ob_start() Cannot use output buffering in output buffering display handlers in ./vendor/symfony/src/Symfony/Component/Yaml/Yaml.php on line 53
1. {closure}() ./FatalHandler.php // <- it's ob_start() closure
...
5. Symfony\Component\HttpKernel\Kernel->boot() ./vendor/bundles/Gtt/Bundle/Core/Kernel/LazyKernel.php:47
6. Symfony\Component\HttpKernel\Kernel->initializeContainer()./vendor/symfony/src/Symfony/Component/HttpKernel/Kernel.php:127
7. Symfony\Component\HttpKernel\Kernel->buildContainer() ./vendor/symfony/src/Symfony/Component/HttpKernel/Kernel.php:545
8. Gtt\Bundle\Core\Kernel\DefaultKernel->registerContainerConfiguration() ./vendor/symfony/src/Symfony/Component/HttpKernel/Kernel.php:644 // <-- registerContainerConfiguration() method just use another path for configs
9. Symfony\Component\Config\Loader\DelegatingLoader->load() ./vendor/bundles/Gtt/Bundle/Core/Kernel/DefaultKernel.php:59
10. Symfony\Component\DependencyInjection\Loader\YamlFileLoader->load() ./vendor/symfony/src/Symfony/Component/Config/Loader/DelegatingLoader.php:50
11. Symfony\Component\DependencyInjection\Loader\YamlFileLoader->loadFile() ./vendor/symfony/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php:42
12. Symfony\Component\Yaml\Yaml::parse() ./vendor/symfony/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php:231
13. ob_start() ./vendor/symfony/src/Symfony/Component/Yaml/Yaml.php:53

Can you rewrite parsing of Yaml with file_get_contents() and do not use include for that because it's can break security of application and give the possibility of local includes.