Open RJ opened 3 years ago
Comment written by John Wright on 10/29/2008 21:02:52
Do you all use Thrift at Facebook to serialize PHP objects? It comes with built-in PHP and Erlang generators.
Comment written by RJ on 10/30/2008 13:38:26
Erm, I don't know exactly what facebook do, but i think i read somewhere that they do use thrift for serializing php objects, yes.
Sadly changing our php serialization format isn't gonna happen, hence the need for the above code.
Comment written by Andy Skelton on 01/16/2009 04:44:55
Thanks! I used this code in a gen_server that provides PHP eval access within Erlang. Under what license do you release this?
Comment written by Andy Skelton on 01/19/2009 22:48:11
I didn't see the low-contrast message in the footer before. GPLv2 then. Thanks.
Comment written by RJ on 02/05/2009 14:07:12
Yep GPLv2 - i should make that more visible.
I've also rolled a php-eval server in erlang, maybe i'll dust it off and publish it soon :)
Comment written by myracer on 10/24/2009 11:57:39
I have a good fresh joke for you! What did the elephant say to the naked man? It's cute, but can you pick up peanuts with it?
___________________________
--/ viagara generic /--
Comment written by emilio on 11/04/2009 23:04:54
I am having a hard time deciphering the serialized string. In your example above, your array is serialized as:
a:4:{i:0;i:123;i:1;s:5:"hello";...
this is confusing to me. if the syntax is i:0 means index = 0, and i:123 means the value at [0] = 123, how does unserialize know whether the i: means the index or the value?
sorry if thats a dumb question, i can't find any information about this syntax anywhere.
Comment written by emilio on 11/04/2009 23:19:11
sorry, I forgot to add:
and why in the second array is there not an i:0? eg.
a:2:{s:1:"a";....
based on the first portion of the code, I would have expected:
a:2:{i:0;s:1:"a";
why is there no reference to index in the second array?
thanks for any advice, and if you can point me to a reference I would be VERY grateful because I have large, complex data structure serialized (composed of many objects and data types) and its a little hairy at the moment.
Comment written by myrnacid on 11/12/2009 15:22:09
Sorry, for off top, i wanna tell one joke) What do you get if you cross a giant and a vampire? A BIG pain in the neck!
___________________________
--/ viagera buy Illinois /--
Comment written by sjolzy on 12/22/2010 01:28:42
<?php
$host = "127.0.0.1";
$port = 1187;
$fp = stream_socket_client("tcp://$host:$port", $errno, $errstr, 2);
if (!$fp) {
echo "$errstr ($errno)\n";
} else {
stream_set_timeout($fp,2);
get_line($fp);
put_line($fp,"SYSMSG,bobo,Hi boy");
fclose($fp);
}
function get_line($handle){
while(!feof($handle)){
$buff =fread($handle,2);
$head =unpack("H*",$buff);
return fread($handle,hexdec($head[1]));
}
}
function put_line($handle,$data){
$body=pack("A*",$data);
$len=strlen($body);
$head=pack("H*",to_hex_str($len));
fwrite($handle,$head.$body);
}
function to_hex_str($num){
$str =dechex($num);
$str =str_repeat('0',4-strlen($str)).$str;
return $str;
}
?>
This is what I used
Comment written by php developers on 04/30/2011 13:09:19
Keep up the good Business to Business posts- great work.
Comment written by Jason Judge on 07/07/2015 09:50:57
Six years later, I'll give a reply: because they come in pairs. a:4:{key;value;key;value} Both the keys and values can be various different data types (e.g. int, string and even null for the key, and *anything* of any complexity for the value).
Just had to work this out for a serialized data parser I've written for PHP: https://github.com/academe/...
Comment written by Jason Judge on 07/07/2015 09:55:20
PHP "arrays" can be a numeric indexed array as you know in many other languages, or a dictionary with strings as keys, or even a mix of the two. PHP just calls them "arrays", but they are more than that. Here you are looking at {"a": 3, "foo": "b", 4: "bar"} in a json-ish format.
Written on 09/27/2008 22:42:20
URL: http://www.metabrew.com/article/reading-serialized-php-objects-from-erlang