php-src icon indicating copy to clipboard operation
php-src copied to clipboard

ob_start('ob_gzhandler') in 8.1.4 fails

Open jochensengier opened this issue 4 years ago • 7 comments

Description

The following code at the top:

<?php ob_start('ob_gzhandler');?>

Resulted in this output:

cannot decode raw data / content-encoding error

Making the website completely inaccessible/unavailable.

PHP Version

PHP 8.1.4

Operating System

No response

jochensengier avatar Mar 17 '22 09:03 jochensengier

I cannot reproduce that. Can you please provide more details, such as a complete reproduce script, and the Webserver's response? Also, which browser(s) do you use?

cmb69 avatar Mar 17 '22 13:03 cmb69

This is a website running Laravel v9.5.1 on PHP 8.1.4 https://www.vandelanotte.be/en

If you navigate to: https://www.vandelanotte.be/en?debug=1 It will execute ob_start('ob_gzhandler'); at the top of the page/script and you'll see a content encoding error in every browser. The ob_start function is something I've been using for over a decade on various Laravel and PHP versions.

GET /en HTTP/1.1 Host: www.vandelanotte.be Returns headers, response, ...

GET /en?debug=1 HTTP/1.1 Host: www.vandelanotte.be Returns nothing, except an error.

After some debugging, I found in one of the server logs that there's a deprecation error/warning, perhaps that is causing the issue? I noticed some PRs in this new version regarding ob_clean, maybe it's worth checking those out?

[Thu Mar 17 14:37:35.363334 2022] [error] [pid 3226378] mod_proxy_fcgi.c(887): [client :0] AH01071: Got error 'PHP message: PHP Deprecated: Return type of ....'

I know it's difficult to debug these kind of issues, so I really appreciate the effort and time you're putting into this.

jochensengier avatar Mar 17 '22 13:03 jochensengier

Hard to tell what's actually happening without having a reproducer. Since this is a Laravel app, consider to ask in some Laravel support forum; somebody else might have had the same issue, and possibly already a solution (or at least a way to more easily reproduce the problem). Also consider to use the INI directive zlib.output_compression instead of ob_start('ob_gzhandler') (the former is preferable anyway).

cmb69 avatar Mar 17 '22 14:03 cmb69

No it's definitely not a Laravel issue. I'm having the same issue on older PHP versions (7.4.x, 8.0.x) and non Laravel websites as well.

Must be some kind of server configuration that's been changed across multiple hosting companies ...

jochensengier avatar Mar 18 '22 08:03 jochensengier

I have the same problem with ob_start('ob_gzhandler') and not Laravel websites as well. With PHP 8.1.4 or PHP 8.0.17 my backend doesn't work properly when I try to reply with a JSON that contains a base64 encoded string. If I remove the line "ob_start('ob_gzhandler')" everything works properly.

With PHP 8.0.16 or PHP 8.1.3 everything works good with "ob_start('ob_gzhandler')" command.

piccio85 avatar Apr 21 '22 08:04 piccio85

After a while I found the reason of this issue. I've included a file that begins from rows 2 instead of row 1.

The following file make ob_gzhandler not working properly: image

I changed the file removing the first line: image

Now it works.

supportoMambu avatar Jun 15 '23 06:06 supportoMambu

@supportoMambu that's not causing the original issue. Most php devs will know that you have to call ob_start before ANY output (including blank lines).

jochensengier avatar Jun 15 '23 06:06 jochensengier