note 46313 added to function.serialize
| From: | brooklynphilhotmailcom at osu1 dot php dot net | Date: | Wed, 06 Oct 2004 20:07:40 +0000 |
| Subject: | note 46313 added to function.serialize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78096@lists.php.net to get a copy of this message | ||
In my experience of the (far and few in between) times when it is necessary to store large
(megabytes) amounts of data in a php-readable ascii file format, using var_export() and require() is
much faster serialize() and unserialize(file_get_contents()) (I have tested it on classes
encapsulating arrays, i.e. <?php class blah { $a = array(megsofstuffhere); $b =
array(megsofstuffhere); $c=... }; $data = new blah ?>) (var_export is also more readable and
notepadable than serialize!)
However, since var_export produces only the rvalue (or uninstantiation), of the data needed, dont
forget to cosmetically modify output of var_export( , true): in case of classes, you will need to
use "$var = new classname" (and rename a possible stdClass) and in case of arrays, etc,
just use "$var = ".var_export(). The file being var_export()ed to and require()ed must
also be encapculated in "<?php ?>" when written to (or else its just dumped to
browser/stdout as a textfile).
Hope this helps :)
--Phil
P.S. (in cases of small amounts of data, serialize is better, especially for cross-URL data
transport using <?php base64_encode(gzdeflate(serialize()))?>)
----
Manual Page -- http://www.php.net/manual/en/function.serialize.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46313
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46313&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46313&report=yes
Search -- http://master.php.net/manage/user-notes.php