thirsty93
thirsty93

Reputation: 2652

PHP unserialize keeps throwing same error over 100 times

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?

Upvotes: 0

Views: 2577

Answers (4)

mike
mike

Reputation: 5213

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

[email protected]

Upvotes: 0

Gerald
Gerald

Reputation: 23499

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.

Upvotes: 0

dirtside
dirtside

Reputation: 8270

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.

Upvotes: 3

Daniel Papasian
Daniel Papasian

Reputation: 16423

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.

Upvotes: 5

Related Questions