Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>How can i store my very complex objects without serializing them, or how can I make my unserialization faster?</p> </blockquote> <p>If you need PHP objects that are not <a href="http://php.net/manual/en/reserved.classes.php" rel="nofollow noreferrer"><code>stdClass</code></a> (you have class definitions next to data-members) you need to use any kind of PHP compatible serialization.</p> <p>Independent to the PHP language, serialization comes with a price because it is data transformation and mapping. If you have a large amount of data that needs to be transposed from and into string (binary) information, it takes its processing and memory.</p> <p>By default is PHP's built-in serialization that you make use with <code>serialize</code> and <code>unserialize</code>. PHP offers two default serialization types. Other extensions offer something similar. Related question:</p> <ul> <li><a href="https://stackoverflow.com/q/6722874/367456">What is the <code>php_binary</code> serialization handler?</a></li> </ul> <p>As you've said you need some kind of serialization and unserializing is the bottleneck, you could consider to choose another serializer like <em>igbinary</em>.</p> <p>However, storing PHP in flat files works, too. See <a href="http://php.net/var_export" rel="nofollow noreferrer"><code>var_export</code></a>:</p> <pre><code>// storing file_put_contents( 'name-of-data.php', '&lt;?php return ' . var_export($data, true) . ';' ); </code></pre> <p>This example stores data in a format that PHP can read the file back in. Useful for structured data in forms of stdClass objects and arrays. Reading this back in is pretty straight forward:</p> <pre><code>// reading $data = include('name-of-data.php'); </code></pre> <p>If you put the PHP code into the database, you don't need the <code>&lt;?php</code> prefix:</p> <pre><code>// storing $string = 'return ' . var_export($data, true) . ';'; $db-&gt;store($key, $string); // reading $string = $db-&gt;read($key); $data = eval($string); </code></pre> <p>The benefit of using <code>var_export</code> is that you make use of PHP itself to parse the data. It's normally faster than <code>serialize</code> / <code>unserialize</code> but for your case you need to metric that anyway.</p> <p>I suggest you try with <code>var_export</code> how it behaves in terms of file-size and speed. And also with igbinary. Compare then. Leave the updated information with your question when you gather it, so additional suggestion can be given in case this does not solve your issue.</p> <p>Another thing that comes to mind is using the Json format. Some data-stores are optimized for it, so you can query the store directly. Also the map-reduce methodology can be used with many of these data-stores so you can spread processing of the data. That's something you won't get straight with <code>serialize</code>/<code>unserialize</code> as it's always processing one big chunk of data at a time, you can not differ.</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.
    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