# Serialization PHP - C++ (boost?)

This topic is 3762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

What i need to do is this: Have a php file in a webserver, doing a POST with binary payload to a fast-cgi written in c++, and the c++ should deserialize that payload into a known struct. I've been playing around with boost::serialization, but i can't seem to comprehend the binary format it generates (So i could hardcode the php to make a valid payload to be deserialised from the fast-cgi). And not so important: i've noticed boost::serialization to binary archives always look like: serialization::archive ÃõH@ can't i get rid of the "serialization::archive" thing that is obviusly not part of the struct i just serialized? Thanks a lot for your help. I'd appreciate any other ideas to accomplish the same result :).

##### Share on other sites
What's the known struct?

##### Share on other sites
it can be anything. like...

struct whatever
{
int a;
int b;
float c;
std::vector<int> d;
}

(mainly structs consisting of basic types and collections of basic types)

i'm trying to implement something like an RPC or webservice. and the struct would be mainly a way to pass all the parameters in a binary manner, so i could either just cast it to the struct i know it is, or deserialize it with boost::serialization, or something like that :).

did i make myself clear?

##### Share on other sites
I see. In that case, I would suggest using an XML serialization format, and compressing it. XML is easier to parse (and more standard) than binary formats, yet not really heavier when compressed, plus boost should be able to read it.

Alternately, you may design your own archive format for boost.

##### Share on other sites
i see.

xml is not an option for now. im actually doing all this to bypass using a webservice/SOAP/xml, etc.

this should be real fast :)

i'll take a look at making my own archive type. i hope it's not very complicated, otherwise ill have to do something uglyer, like casting :P.

##### Share on other sites
Quote:
 Original post by ElPeque2i'll take a look at making my own archive type. i hope it's not very complicated, otherwise ill have to do something uglyer, like casting :P.

Casting wouldn't work, for endianness reasons. This is precisely what boost allows you to circumvent.

##### Share on other sites
Ice.

Quote:
 this should be real fast :)

In what way? You'll need to be on gigabit network before PHP + C++ combined become a bottle-neck.

But either way, the overhead of HTTP (edit), or the size of payload will determine the cost, very rarely the encoding.

##### Share on other sites
Quote:
 Original post by AntheusBut either way, the overhead of HTML
HTTP?

##### Share on other sites
Casting would still be trouble if i will only be using x86 systems? And if i were to migrate, then it would all switch to x64.

And it's interesting what you say about where the bottlenecks would be. My intuition tells me that passing xmls should be very inefficient. (much more data, maybe compress, decode, etc). Any past experiences?

##### Share on other sites
Quote:
 Original post by ElPeque2And it's interesting what you say about where the bottlenecks would be. My intuition tells me that passing xmls should be very inefficient. (much more data, maybe compress, decode, etc). Any past experiences?

Let's say you are sending 3 ints over the wire. They take 12 bytes in binary encoding.

The POST looks like this:
POST /some_path HTTP/1.0Content-type: multipart/form-data, boundary=ABCDLKHsadfhiueakjhg--ABCD

First, you need to MIME encode it, which will likely result in increased size of 4/3 (16 bytes).
Second, you need to form a valid POST request (100 bytes).
Third, you need to send this as TCP packet (120 bytes).
Then the IP header (140 bytes).

And suddenly, your compact, optimal, efficient 12 bytes resulted in 140 bytes on the wire.

HTTP isn't designed for efficiency, so unless you're sending proportionally enough data (tens of kilobytes per request), it will be horribly inefficient.

Even more, encoding data as text and passing it as URL parameters in POST will be much more efficient for in many cases, even if not binary encoded.

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 13
• 14
• 9
• ### Forum Statistics

• Total Topics
633365
• Total Posts
3011520
• ### Who's Online (See full list)

There are no registered users currently online

×