zlib.output_compressions does not work because of split mod_php5/php5-zlib

Vasil Dimov vd at datamax.bg
Wed Apr 13 15:28:49 UTC 2005


As noted in

http://www.freebsd.org/cgi/query-pr.cgi?pr=76331

The problem is that PHP outputs "Content-Encoding: gzip" header only if
zlib is enabled at compile time. Which is not the case with the FreeBSD
port - zlib support is installed as separate port(s): archivers/php[45]-zlib.

So zlib.output_compression=On is unusable because of the missing
header.

So we have the following 2 choises:
1. Enable zlib in php at compile time and remove archivers/php[45]-zlib
ports (poor).
2. Change PHP source to output the headers mentioned even if zlib is not
enabled at compile time.

Fortunately the second is very easy to achieve due to the well-written
PHP code. As seen in the included patch just "#if HAVE_ZLIB" must be
removed from SAPI.c. What happens is that

zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)

is always false when zlib is not loaded even if zlib.output_compression
is turned on in php.ini and so - no extra headers or errors appear when
zlib.output_compression=On and no zlib.so extension is loaded.

E.g. #if HAVE_ZLIB is not needed at all in the places where it is
removed in the included patch. Probably this should be emailed to the
PHP developers for review and inclusion in the next releases.

The same patch can be appiled and is valid for PHP4 and PHP5.


--- SAPI.c.orig	Wed Apr 13 17:06:11 2005
+++ SAPI.c	Wed Apr 13 17:43:58 2005
@@ -565,11 +565,18 @@
 					ptr++;
 					len--;
 				}
+/*
+ * Will not hurt in any way if we do not have zlib installed.
+ * This code is allowed to make it possible to use zlib as a
+ * runtime extension (HAVE_ZLIB not defined at compile time).
 #if HAVE_ZLIB
+*/
 				if(!strncmp(ptr, "image/", sizeof("image/")-1)) {
 					zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"), "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
 				}
+/*
 #endif
+*/
 				mimetype = estrdup(ptr);
 				newlen = sapi_apply_default_charset(&mimetype, len TSRMLS_CC);
 				if (!SG(sapi_headers).mimetype){
@@ -712,7 +719,12 @@
 		return SUCCESS;
 	}
 
+/*
+ * Output zlib related headers even if zlib is not enabled at compile time.
+ * This code is allowed to make it possible to use zlib as a
+ * runtime extension (HAVE_ZLIB not defined at compile time).
 #if HAVE_ZLIB
+*/
 	/* Add output compression headers at this late stage in order to make
 	   it possible to switch it off inside the script. */
 
@@ -740,7 +752,9 @@
 			zval_ptr_dtor(&uf_result);
 		}
 	}
+/*
 #endif
+*/
 
 	/* Success-oriented.  We set headers_sent to 1 here to avoid an infinite loop
 	 * in case of an error situation.
-------------- next part --------------
--- SAPI.c.orig	Wed Apr 13 17:06:11 2005
+++ SAPI.c	Wed Apr 13 17:43:58 2005
@@ -565,11 +565,18 @@
 					ptr++;
 					len--;
 				}
+/*
+ * Will not hurt in any way if we do not have zlib installed.
+ * This code is allowed to make it possible to use zlib as a
+ * runtime extension (HAVE_ZLIB not defined at compile time).
 #if HAVE_ZLIB
+*/
 				if(!strncmp(ptr, "image/", sizeof("image/")-1)) {
 					zend_alter_ini_entry("zlib.output_compression", sizeof("zlib.output_compression"), "0", sizeof("0") - 1, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
 				}
+/*
 #endif
+*/
 				mimetype = estrdup(ptr);
 				newlen = sapi_apply_default_charset(&mimetype, len TSRMLS_CC);
 				if (!SG(sapi_headers).mimetype){
@@ -712,7 +719,12 @@
 		return SUCCESS;
 	}
 
+/*
+ * Output zlib related headers even if zlib is not enabled at compile time.
+ * This code is allowed to make it possible to use zlib as a
+ * runtime extension (HAVE_ZLIB not defined at compile time).
 #if HAVE_ZLIB
+*/
 	/* Add output compression headers at this late stage in order to make
 	   it possible to switch it off inside the script. */
 
@@ -740,7 +752,9 @@
 			zval_ptr_dtor(&uf_result);
 		}
 	}
+/*
 #endif
+*/
 
 	/* Success-oriented.  We set headers_sent to 1 here to avoid an infinite loop
 	 * in case of an error situation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 155 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-ports-bugs/attachments/20050413/72247457/attachment.sig>


More information about the freebsd-ports-bugs mailing list