TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-14-2009, 10:49 PM   #1 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default 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 .
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 06-14-2009, 11:25 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,324
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
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 ?).
Salathe is offline  
Reply With Quote
Old 06-14-2009, 11:27 PM   #3 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

...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.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 06-14-2009, 11:39 PM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,324
Thanks: 5
Salathe is on a distinguished road
Default

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.
Salathe is offline  
Reply With Quote
Old 06-15-2009, 12:58 AM   #5 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

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...
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:08 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design