Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Effective compression in AS3 to be transeferred to PHP

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 received, 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,

like image 665
Björn Avatar asked Sep 11 '09 13:09

Björn


2 Answers

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 :)

like image 64
AdobeTed Avatar answered Nov 15 '22 15:11

AdobeTed


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_Amf+-+Wade+Arnold

like image 24
Steven Mercatante Avatar answered Nov 15 '22 17:11

Steven Mercatante