Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll want to use <code>RiakBucket::newBinary()</code> and <code>RiakBucket::getBinary()</code> if you want to store unencoded binary data into Riak with the PHP client.</p> <pre><code>$image = file_get_contents("images/TagLabs-Logo-White-240x60.png"); $md5 = md5($image); $riak-&gt;bucket("test") -&gt;newObject("image_base64", base64_encode($image)) -&gt;store(); $riak-&gt;bucket("test") -&gt;newBinary("image_raw", $image, 'image/png') -&gt;store(); $b64Read = $riak-&gt;bucket("test")-&gt;get("image_base64"); echo "B64 md5 comparison: original=$md5, b64=".md5(base64_decode($b64Read-&gt;getData()))."\n"; $rawRead = $riak-&gt;bucket("test")-&gt;getBinary("image_raw"); echo "Raw md5 comparison: original=$md5, raw=".md5($rawRead-&gt;getData())."\n"; </code></pre> <p>Produces output:</p> <pre><code>B64 md5 comparison: original=6749cfaf1516b01db9792e119d53177a, b64=6749cfaf1516b01db9792e119d53177a Raw md5 comparison: original=6749cfaf1516b01db9792e119d53177a, raw=6749cfaf1516b01db9792e119d53177a </code></pre> <p>In my performance tests, both approaches have basically the same overhead from Riak's perspective. Spending cycles on base64 encoding / decoding (plus under the hood, the base64 data is then json encoded/decoded) puts the binary approach ahead overall.</p> <p>Edit: Also note that there's a ~50mb upper limit for data stored in a Riak binary object (see <a href="https://stackoverflow.com/questions/6102940/downsides-of-storing-binary-data-in-riak">this post</a>) due to a limitation in the Erlang backend. Realistically if you're getting anywhere near that, you might want to rethink how you're storing those images, that's a lot of data to send on the pipe if you're accessing those frequently, something like NFS or another local filesystem cache is probably a better idea.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload