<!-- 
RSS generated by JIRA (5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9) at Wed May 22 23:06:06 CDT 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.couchbase.com/issues/si/jira.issueviews:issue-xml/PCBC-78/PCBC-78.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Couchbase</title>
    <link>http://www.couchbase.com/issues</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.4</version>
        <build-number>845</build-number>
        <build-date>26-12-2012</build-date>
    </build-info>

<item>
            <title>[PCBC-78] PHP value compression incompatible with Java/.NET</title>
                <link>http://www.couchbase.com/issues/browse/PCBC-78</link>
                <project id="10049" key="PCBC">Couchbase PHP client library</project>
                        <description>A customer has reported a bug in Couchbase&amp;#39;s PHP client code. The code referred to is actually a compiled C module that PHP talks to. This bug is related to uncompressed JSON content originating from Java/.NET/ETC clients.&lt;br/&gt;
&lt;br/&gt;
Background: When attempting to test PHP fetching of JAVA-originating JSON content from Couchbase, he received errors from the C code that initiates decompression of Couchbase payloads.&lt;br/&gt;
&lt;br/&gt;
After introducing a hack to simply ignore decompression and after fixing a string length bug, everything worked fine.&lt;br/&gt;
&lt;br/&gt;
Here&amp;#39;s where the problem lies and what he did. (Note: All those fprintf() calls are his, and the whitespace formatting problems are due to e-mail loss):&lt;br/&gt;
&lt;br/&gt;
Line 680 of &amp;quot;couchbase.c&amp;quot;&lt;br/&gt;
&lt;br/&gt;
static int php_couchbase_zval_from_payload(zval *value, char *payload, size_t payload_len, unsigned int flags, int serializer TSRMLS_DC) /* {{{ */ {&lt;br/&gt;
int compressor;&lt;br/&gt;
zend_bool payload_emalloc = 0;&lt;br/&gt;
#ifdef HAVE_COMPRESSION&lt;br/&gt;
char *buffer = NULL;&lt;br/&gt;
#endif&lt;br/&gt;
&lt;br/&gt;
fprintf(stdout, &amp;quot;C Code: Entering php_couchbase_zval_from_payload: line 687\n&amp;quot;);&lt;br/&gt;
fprintf(stdout, &amp;quot;C Code: Raw Payload: %s: line 688\n&amp;quot;, payload);&lt;br/&gt;
&lt;br/&gt;
if (payload == NULL &amp;amp;&amp;amp; payload_len &amp;gt; 0) {&lt;br/&gt;
php_error_docref(NULL TSRMLS_CC, E_WARNING,&lt;br/&gt;
&amp;quot;could not handle non-existing value of length %zu&amp;quot;, payload_len);&lt;br/&gt;
return 0;&lt;br/&gt;
} else if (payload == NULL) {&lt;br/&gt;
if ((flags &amp;amp; 127) == IS_BOOL) {&lt;br/&gt;
ZVAL_FALSE(value);&lt;br/&gt;
} else {&lt;br/&gt;
ZVAL_EMPTY_STRING(value);&lt;br/&gt;
}&lt;br/&gt;
return 1;&lt;br/&gt;
}&lt;br/&gt;
&lt;br/&gt;
if ((compressor = COUCHBASE_GET_COMPRESSION(flags))) { #ifdef HAVE_COMPRESSION&lt;br/&gt;
size_t len, length;&lt;br/&gt;
zend_bool decompress_status = 0;&lt;br/&gt;
/* This is copied from pecl-memcached */&lt;br/&gt;
////memcpy(&amp;amp;len, payload, sizeof(size_t));&lt;br/&gt;
len = strlen(payload);&lt;br/&gt;
compressor = 123;&lt;br/&gt;
&lt;br/&gt;
fprintf(stdout, &amp;quot;C Code: Attempting to allocate memory bytes: %i: line 711\n&amp;quot;, len+1);&lt;br/&gt;
buffer = emalloc(len + 1);&lt;br/&gt;
&lt;br/&gt;
////payload_len -= sizeof(size_t);&lt;br/&gt;
////payload += sizeof(size_t);&lt;br/&gt;
length = len;&lt;br/&gt;
&lt;br/&gt;
switch (compressor) {&lt;br/&gt;
case 123:&lt;br/&gt;
////Hack job&lt;br/&gt;
decompress_status = 1;&lt;br/&gt;
length = len;&lt;br/&gt;
memcpy(buffer, payload, len + 1);&lt;br/&gt;
fprintf(stdout, &amp;quot;\n\nHack fix on line 758:\n\n%s\n\n&amp;quot;, buffer);&lt;br/&gt;
&lt;br/&gt;
break;&lt;br/&gt;
case COUCHBASE_COMPRESSION_FASTLZ:&lt;br/&gt;
#ifdef HAVE_COMPRESSION_FASTLZ&lt;br/&gt;
decompress_status = ((length = fastlz_decompress(payload, payload_len, buffer, len)) &amp;gt; 0);&lt;br/&gt;
#else&lt;br/&gt;
php_error_docref(NULL TSRMLS_CC, E_WARNING, &amp;quot;could not decompress value, no fastlz lib support&amp;quot;);&lt;br/&gt;
return 0;&lt;br/&gt;
#endif&lt;br/&gt;
break;&lt;br/&gt;
case COUCHBASE_COMPRESSION_ZLIB:&lt;br/&gt;
#ifdef HAVE_COMPRESSION_ZLIB&lt;br/&gt;
decompress_status = (uncompress((Bytef *)buffer, &amp;amp;length, (Bytef *)payload, payload_len) == Z_OK);&lt;br/&gt;
/* Fall back to &amp;#39;old style decompression&amp;#39; */&lt;br/&gt;
if (!decompress_status) {&lt;br/&gt;
unsigned int factor = 1, maxfactor = 16;&lt;br/&gt;
int status;&lt;br/&gt;
&lt;br/&gt;
do {&lt;br/&gt;
length = (unsigned long)payload_len * (1 &amp;lt;&amp;lt; factor++);&lt;br/&gt;
buffer = erealloc(buffer, length + 1);&lt;br/&gt;
memset(buffer, 0, length + 1);&lt;br/&gt;
status = uncompress((Bytef *)buffer, (uLongf *)&amp;amp;length, (const Bytef *)payload, payload_len);&lt;br/&gt;
} while ((status == Z_BUF_ERROR) &amp;amp;&amp;amp; (factor &amp;lt; maxfactor));&lt;br/&gt;
&lt;br/&gt;
if (status == Z_OK) {&lt;br/&gt;
decompress_status = 1;&lt;br/&gt;
}&lt;br/&gt;
}&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
I believe the ideal mode would be that all Couchbase-supplied clients will default to using compatible methods for storing and retrieving values. Same compression thresholds, and same compression algorithms, by default. That way all of our products will work with each other.&lt;br/&gt;
&lt;br/&gt;
All Couchbase client libraries should have documentation saying how to be compatible with old memcached clients from that language platform that may use a different algorithm. For example, the PHP client should describe what options to set in order to be able to read values from the pecl-memcached extension. That way, upgrading to the Couchbase library will allow readiing data that was saved from an older version. This should be under an &amp;quot;Compatibility with [the non-Couchbase library]&amp;quot; section, and referenced from the &amp;quot;Ugrade&amp;quot; pages as well.&lt;br/&gt;
</description>
                <environment></environment>
            <key id="18031">PCBC-78</key>
            <summary>PHP value compression incompatible with Java/.NET</summary>
                <type id="1" iconUrl="http://www.couchbase.com/issues/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.couchbase.com/issues/images/icons/priorities/major.png">Major</priority>
                    <status id="6" iconUrl="http://www.couchbase.com/issues/images/icons/statuses/closed.png">Closed</status>
                    <resolution id="1">Fixed</resolution>
                    <security id="10011">Public</security>
                        <assignee username="ingenthr">Matt Ingenthron</assignee>
                                <reporter username="TimSmith">Tim Smith</reporter>
                        <labels>
                    </labels>
                <created>Tue, 26 Jun 2012 10:29:47 -0500</created>
                <updated>Fri, 10 Aug 2012 21:31:26 -0500</updated>
                    <resolved>Fri, 10 Aug 2012 21:30:39 -0500</resolved>
                                                            <component>library</component>
                                <votes>0</votes>
                        <watches>0</watches>
                                                    <comments>
                    <comment id="31335" author="ingenthr" created="Tue, 26 Jun 2012 21:48:14 -0500"  >We would like to iterate all of the Couchbase Client libraries forward to use, where possible, common flags to understand data types.  There are legacies we will be living with for some time though, so it won&amp;#39;t be an overnight transition.  Each client library picked flags for itself, without coordination.  We&amp;#39;ll standardize flags in a future release, but then we&amp;#39;ll still have to be able to switch between the two.&lt;br/&gt;
&lt;br/&gt;
The PHP client is supposed to be compatible with pecl-memcached, including compression, out of the box other than where noted in documentation.  If there are parts we&amp;#39;re missing, we need to file documentation bugs.</comment>
                    <comment id="31341" author="ingenthr" created="Tue, 26 Jun 2012 21:56:30 -0500"  >See also &lt;a href=&quot;http://www.couchbase.com/issues/browse/PCBC-77&quot; title=&quot;client should not decompress an already uncompressed array&quot;&gt;&lt;strike&gt;PCBC-77&lt;/strike&gt;&lt;/a&gt;</comment>
                    <comment id="35223" author="ingenthr" created="Fri, 10 Aug 2012 21:30:39 -0500"  >Added as a good approach for now.  We need to come up with a better approach and that&amp;#39;s covered in &lt;a href=&quot;http://www.couchbase.com/issues/browse/PCBC-97&quot; title=&quot;tests 006.phpt and 007.phpt fail on multiple nodes owing to how they compare multi results&quot;&gt;&lt;strike&gt;PCBC-97&lt;/strike&gt;&lt;/a&gt;</comment>
                    <comment id="35224" author="ingenthr" created="Fri, 10 Aug 2012 21:31:26 -0500"  >Correction, that&amp;#39;s covered in &lt;a href=&quot;http://www.couchbase.com/issues/browse/PCBC-96&quot; title=&quot;Create compatibility layer for flags in PHP&quot;&gt;PCBC-96&lt;/a&gt;.  :)</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
                <customfields>
                                                                                                                                                                                                                    <customfield id="customfield_10081" key="com.pyxis.greenhopper.jira:gh-global-rank">
                <customfieldname>Rank</customfieldname>
                <customfieldvalues>
                    <customfieldvalue>9825</customfieldvalue>
                </customfieldvalues>
            </customfield>
                                                                                    <customfield id="customfield_10181" key="com.atlassian.jira.ext.charting:timeinstatus">
                <customfieldname>Time In Status</customfieldname>
                <customfieldvalues>
                    
                </customfieldvalues>
            </customfield>
                                                </customfields>
    </item>
</channel>
</rss>