1

My project has an editor which users will save large text to MySQL. I'm using PHP & Javascript, jQuery. I have been looking, search, google, etc. but found no working example that has BOTH js & php code to compress(&encode) on client side & decompress(&decode) on server side.

I found http://code.kuederle.com/huffman and JSend & some other StackOverflow questions about this topics but they are not working or just do one side only.

Do you have code for both PHP & JS sides to compress & decompress form data? Thanks a lot.

ngduc
  • 1,415
  • 12
  • 17
  • 1
    So you want to compress the text for sending smaller, and then de-compress it on the other side? If I'm right, why do you need to do this? I can see why it would be good with, say, 400 page documents, but even with TinyMCE, who's going to write that much ;-) I don't think you'd have issues with bandwidth, if this is what your question is about. – Bojangles Jun 16 '11 at 21:59
  • It's HTML, not just plain text. It's about 50KB/page, so if I can reduce 500KB bandwidth to 300KB, that'd be great! (for updating speed) – ngduc Jun 17 '11 at 00:38

3 Answers3

1

Try jSend, it supports compression via a jQuery plugin and provides a PHP script. I haven't personally used it however.

mistagrooves
  • 2,337
  • 15
  • 16
  • thanks, as I stated in the post, I have tried it & its php script didn't work. – ngduc Jun 16 '11 at 23:32
  • I downloaded source code, ran a simple $jSEND->getData to decrypted one from its demo site, it didn't decrypted it to the original text :( – ngduc Jun 17 '11 at 15:58
0

There are implementations of LZW in both Javascript and PHP

PHP: http://code.google.com/p/php-lzw/

Javascript: http://marklomas.net/ch-egg/articles/lzwjs.htm

Also see JavaScript implementation of Gzip

Another option to look into, depending on your project needs, is mod_deflate (at least if your are using Apache). But this only compresses data from the server sent to the client.

Community
  • 1
  • 1
JasonCG
  • 889
  • 13
  • 21
  • thanks, I have tried those before asking. They don't have Both Js & PHP versions. I really need Both of them. – ngduc Jun 16 '11 at 23:37
  • @ngduc you are going to have to do a bit of experimentation, JasonCG just gave you both a JS and PHP version of the same algorithm. So, it should work. It's not a nice little package but you have a unique use case that isn't well explored. – mistagrooves Jun 17 '11 at 14:44
  • @mistagrooves: I did that before asking. Maybe I did it wrong or it's hard to make them work. Never mind, I found another better solution. – ngduc Jun 17 '11 at 15:51
0

After many days trying, googling, searching, still couldn't find a good working package for both Js & Php to compress form data, submit & decompress.

I came up another solutions to save a lot of bandwidth for Updating speed. I intended to update delta diff of submitted text, but then it's too hard for me, so I just write some code to detect which lines user is changing & submit just those lines.

Please still answer this question if you find out another better one. Thanks.

ngduc
  • 1,415
  • 12
  • 17