maennchen/ZipStream-PHP

Warning from fwrite

garak opened this issue · 9 comments

garak commented

I have a situation where fwrite in ZipStream https://github.com/maennchen/ZipStream-PHP/blob/master/src/ZipStream.php#L441 is raising a warning, and so everything is failing (because of the sent output).
I cannot say for sure that the problem is a warning since I couldn't find a way to get that information. I only have 2 clues:

  1. when PHP tries to send headers, it says that headers were already sent in the "fwrite" line
  2. if I put error_reporting(E_ALL & ~E_WARNING); in my script, the problem is workarounded

Is there a possible way to solve this without being forced to change error reporting? TIA

  • ZipStream-PHP version: tried with both 2.2.1 and dev-master
  • PHP version: 8.1.9

@garak What is the warning?

garak commented

@maennchen as mentioned before, I don't know.

I think it's pretty crucial that we see what the warning is!

garak commented

I think it's pretty crucial that we see what the warning is!

I totally agree. The problem is that I don't know how to retrieve that warning.
I checked the PHP manual for the "write" function, and it tells nothing about it (except that the function is raising E_WARNING on failure).

@garak Can you share the broken zip file? (The warning is probably in the content...)

garak commented

Here it is

file.zip

Don't you have something in the logs?

garak commented

Don't you have something in the logs?

Only the warning about headers already sent

ErrorException:
Warning: Cannot modify header information - headers already sent by (output started at /var/www/second/vendor/maennchen/zipstream-php/src/ZipStream.php:464)
  at vendor/symfony/http-foundation/Session/SessionUtils.php:57
  at Symfony\Component\HttpFoundation\Session\SessionUtils::popSessionCookie('_csess', 'e4e7ad9a1c0b912f7d4bad9649acb4c1')
     (vendor/symfony/http-kernel/EventListener/AbstractSessionListener.php:153)
  at Symfony\Component\HttpKernel\EventListener\AbstractSessionListener->onKernelResponse(object(ResponseEvent), 'kernel.response', object(TraceableEventDispatcher))
     (vendor/symfony/event-dispatcher/Debug/WrappedListener.php:117)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(ResponseEvent), 'kernel.response', object(TraceableEventDispatcher))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.response', object(ResponseEvent))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(ResponseEvent), 'kernel.response')
     (vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:154)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch(object(ResponseEvent), 'kernel.response')
     (vendor/symfony/http-kernel/HttpKernel.php:185)
  at Symfony\Component\HttpKernel\HttpKernel->filterResponse(object(ZipResponse), object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:173)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:74)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:202)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:35)
  at require_once('/var/www/second/vendor/autoload_runtime.php')
     (public/index.php:6)

apparently there's some session cookie thing going on in symfony after the zip has already started.

Are you using STreamedResponse? https://github.com/maennchen/ZipStream-PHP/wiki/Symfony-example