Question

I have a large 2d array that I serialize and base64_encode and throw into a database. On a different page I pull the array out and when I base64_decode the serialized array I can echo it out and it definitely looks valid.

However, if I try to unserialize(base64_decode($serializedArray)) it just throws the same error to the point of nearly crashing Firefox.

The error is:

Warning: unserialize() [function.unserialize]: Node no longer exists in /var/www/dev/wc_paul/inc/analyzerTester.php on line 24

I would include the entire serialized array that I echo out but last time I tried that on this form it crashed my Firefox.

Does anyone have any idea why this might be happening?

Was it helpful?

Solution

Are you sure you're just serializing an array, and not an object (e.g. DOMNode?) Like resources, not all classes are going to be happy with being unserialized. As an example with the DOM (which your error suggests to me you're working with), every node has a reference to the parentNode, and if the parentNode doesn't exist at the moment a node is being unserialized, it's not able to recreate that reference and problems ensue.

I would suggest saving the dom tree as XML to the database and loading it back later.

OTHER TIPS

Make sure that the database field is large enough to hold the serialized array. Serialized data is very space-inefficient in PHP, and many DBs (like MySQL) will silently truncate field values that are too long.

What type of elements are in your array? serialize/unserialize does not work with built-in PHP objects, and that is usually the cause of that error.

Also, based on your comment this isn't your problem, but to save space in your database don't base64 encode the data, just escape it. i.e. for mysql use mysql_real_escape_string.

Make sure you don't serialize resources, they can't be serialized.

Resources@php.net

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top