TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   pack (http://www.talkphp.com/advanced-php-programming/4552-pack.html)

xenon 06-14-2009 09:49 PM

pack
 
How does actually this pack() function in PHP work? I'm thinking about creating a caching mechanism (DB based), to store some big objects (or arrays) collected during an application cycle lifetime. That's not important though: the PHP serialize/unserialize method has some flaws in it, meaning that for example I serialize a \n character, the resulting string will not be unserializable. So, then I thought I could pack my data in a binary form (using pack), then store it into the database. This is part of a larger test, in which the objective is to "compile" PHP code to binary code and run that instead of the interpreted PHP code.

So, where could I find some good info about pack? The info the php.net website offers is very limitative... :(

Quote:

Originally Posted by php.net
Pack given arguments into binary string according to format .


Salathe 06-14-2009 10:25 PM

Quote:

Originally Posted by xenon (Post 25409)
How does actually this pack() function in PHP work? I'm thinking about creating a caching mechanism (DB based), to store some big objects (or arrays) collected during an application cycle lifetime. That's not important though: the PHP serialize/unserialize method has some flaws in it, meaning that for example I serialize a \n character, the resulting string will not be unserializable. So, then I thought I could pack my data in a binary form (using pack), then store it into the database. This is part of a larger test, in which the objective is to "compile" PHP code to binary code and run that instead of the interpreted PHP code.

So, where could I find some good info about pack? The info the php.net website offers is very limitative... :(

pack simply takes a formatting string and any number of other arguments to be packed into the binary string result. Of course, that's not much of an explanation! A little bit more information, though not a lot, can be found here or you can look at the Perl pack for comparison (though it is not 100% identical).

I'm more intrigued as to why you think that serialize/unserialize has flaws with regards to not being able to unserialize a serialized value. Can you give an example of when this doesn't work?

On the topic of compiling PHP code into some form of binary, I'm not sure of your purpose here (purely to see if you can do it, or ?).

xenon 06-14-2009 10:27 PM

...and check how much faster (or slower) it is...

Here's an example with serialize/unserialize failing:

PHP Code:

$array = array(=> 'one'"some kind of text\nanother line");

$serialized serialize($array); // it's broken

unserialize($serialized); // fails to unserialize it 

though that simple example works...the problem is with big objects containing alot of properties.

thanks for the links.

Salathe 06-14-2009 10:39 PM

Sorry but I cannot see where the serialized string is broken, can you clarify for me why you think it is broken? Unserializing that serialized string results in exactly the same array as the original one.

xenon 06-14-2009 11:58 PM

I can't find a record that doesn't work correctly right now in the db (it's late and the table has about ~5800 records). I'll just look some more over Google and see what I can find about pack...


All times are GMT. The time now is 06:38 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0