Xajax 0.2: Tips and Tricks: xajax 0.2 and ob gzhandler






Xajax 0.2: Tips and Tricks: xajax 0.2 and ob gzhandler

[edit] xajax version 0.2 - 0.2.1

During xajax 0.2 development xajax users discovered that if they had php output buffering turned on and accidentally had a blank line before the <?php tag in their script, it would make the xml responses returned by xajax invalid. In order to prevent this bug, some output buffer clearing code was added to xajax, right before it returns the response.

It was only after xajax 0.2 was released that users discovered that this output buffer cleaning code also broke xajax if php output compression using gzip or zlib was turned on:

//ini_set('zlib.output_compression_level', 1);
ob_start('ob_gzhandler');

In the discussion that led up to the change, fears that the new code could cause this kind of unintended consequence prompted safeguards to be put in place that make the output buffer cleaning code optional.

If you are using versions 0.2 or 0.2.1 and you want to use php output compression with xajax you will need to add the following line after you instantiate the xajax object:

$xajax->cleanBufferOff();

[edit] xajax 0.2.3

Starting in version 0.2.3 the buffer cleaning functionality is off by default, so xajax test and examples should work out of the box even if you have compression enabled in your PHP configuration. If you find that your xajax response XML is invalid for no apparent reason, it is possible that you have whitespace outside of your <?php  ?> tags in one or more of your source files. The best solution is to find and remove the whitespace. If time or other constraints make that difficult, you can enable the automatic buffer cleaning functionality:

$xajax->cleanBufferOn();

Remember that by enabling the buffer cleaning, you will not be able to use compression.