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.
The other way is to use flash.utils.ByteArray. The ByteArray Class contains zlib compression via the ‘compress’ method.
- Create a new ByteArray.
- Write string into ByteArray.
- Call ByteArray.compress to zlib compress the contents within the ByteArray.
- Post ByteArray to server.
PHP supports zlib so uncompressing the binary data to a string server side is pretty straightforward.
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