views:

515

answers:

2

Hi all!

I need to send some pretty long strings from a flash application to a PHP page, and of course I want to compress it to reduce the traffic load to/from the server. How can I compress the string in an effective way and easily decompress it in PHP?

As it looks now, we're leaning towards standard zip file transfer, but the functionality in PHP to handle this operation are somewhat heavy. When the zip stream is recieved, I have to create a file from that stream - and after that read the file with zip_*-functions.

It would be much more handy and pretty to operate on the string directly.

Best regards,

+3  A: 

Have you looked into AMF (Action Message Format)?

Action Message Format(AMF) is a binary file format representing a serialized ActionScript object. The AMF file type is used throughout the Flash Player for data storage and data exchange. For example in the Flash Player AMF is used in SharedObjects, RemoteObjects, LocalConnection, ByteArray, RTMP, and all RPC operations.

Wade Arnold is responsible for an AMFPHP library that has since been packaged into the Zend Framework. You can use it independently of the framework, however. Here's some more info on it: http://framework.zend.com/wiki/display/ZFPROP/Zend%5FAmf+-+Wade+Arnold

Arms
+7  A: 

The other way is to use flash.utils.ByteArray. The ByteArray Class contains zlib compression via the 'compress' method.

Basically:

  1. Create a new ByteArray.
  2. Write string into ByteArray.
  3. Call ByteArray.compress to zlib compress the contents within the ByteArray.
  4. Post ByteArray to server.

PHP supports zlib so uncompressing the binary data to a string server side is pretty straightforward.

Cheers,

Ted :)

AdobeTed
Leave it to someone from Adobe to one-up me ;)Joking aside, this is some valuable information, and I'll be sure to bookmark it.
Arms