0

--

I have a serialized array sent to another function in my application. Then I try to unserialize the data and present it in another place.

The unserialize function works correctly for smaller ammout of data, like couple of hundreds records. When it comes to 3000+ records I've got the following error message:

Notice (8): unserialize() [function.unserialize]: Error at offset 23048 of 3499833 bytes [APP/controllers/jobs_controller.php, line 475]

Warning (2): Cannot modify header information - headers already sent by (output started at /home/v/s/vsdev/web/public_html/cake/libs/debugger.php:683) [APP/views/helpers/xls.php, line 19]

Warning (2): Cannot modify header information - headers already sent by (output started at /home/v/s/vsdev/web/public_html/cake/libs/debugger.php:683) [APP/views/helpers/xls.php, line 20]

Warning (2): Cannot modify header information - headers already sent by (output started at /home/v/s/vsdev/web/public_html/cake/libs/debugger.php:683) [APP/views/helpers/xls.php, line 21]

Warning (2): Cannot modify header information - headers already sent by (output started at /home/v/s/vsdev/web/public_html/cake/libs/debugger.php:683) [APP/views/helpers/xls.php, line 22]

Warning (2): Cannot modify header information - headers already sent by (output started at /home/v/s/vsdev/web/public_html/cake/libs/debugger.php:683) [APP/views/helpers/xls.php, line 23]

Warning (2): Cannot modify header information - headers already sent by (output started at /home/v/s/vsdev/web/public_html/cake/libs/debugger.php:683) [APP/views/helpers/xls.php, line 24]

Warning (2): Cannot modify header information - headers already sent by (output started at /home/v/s/vsdev/web/public_html/cake/libs/debugger.php:683) [APP/views/helpers/xls.php, line 25]

Link Job Job Ref Company Link Profession Specialism Sub Specialism Zone Country Region City Seniority Date Published Date Archived Days Active Email Enabled Created Modified

Warning (2): Invalid argument supplied for foreach() [APP/views/jobs/search_export.ctp, line 37]

What's wrong?

Piotr Chabros
  • 475
  • 3
  • 17
  • 1
    You need to examine the unserialized/raw string at offset 23048 (1 offset = 1 character) and go from there. It's likely there is a problem with (or before) `serialize()` not `unserialize()` – Mike B Oct 15 '11 at 16:05
  • See : http://stackoverflow.com/a/10152996/1226894 – Baba Oct 03 '12 at 15:19

1 Answers1

1

The data in the record that throws the error is almost certainly corrupted. This should have nothing to do with the number of records you request, just one or more specific records that have invalid serialized data. Try finding out which record results in the error, and check its data.

On a side note: What column type are you using to store your serialized data? I've found that when using TEXT in MySQL, serialized data can be irreversibly damaged by the operations MySQL performs on text, resulting in unserialize() errors. Use BLOB for serialized data columns, that way the data remains unchanged.

Elte Hupkes
  • 2,773
  • 2
  • 23
  • 18
  • I don't store the serialized data. I only serialize it so I can send it and reopen it in another function. – Piotr Chabros Oct 17 '11 at 10:17
  • Why would you serialize data if you're not storing it? – Elte Hupkes Oct 18 '11 at 13:15
  • I have a search. It is a query, and a result of this query is an array. To display the results I have a loop going through the array. On the bottom there is a button "export results". This functionality gives me possibility to export the results. To do that I need to serialize the results so I can send it as a hidden value, then unserialize it in the .xls view. – Piotr Chabros Oct 18 '11 at 13:24
  • Ah, well that explains that. Sending around data like that is hardly ever a good idea though.. It looks as if the amount of data might be a little too much to handle for serialize, or is corrupted somehow because of its size (in your example, it's over 3mb). Could you not rather pass the search criteria to the exporter script, and redo the query? – Elte Hupkes Oct 18 '11 at 13:39