The problem:
- We need to serilize an array into a short string, the shorter the better.
- The importance is more reflected on the bigger array than the smaller one.
- The string will be used in a get request so it has to be url decoded.
Current code snippet
/*
array (size=3)
0 => string '/js/dhdbm78hdfb.js' (length=18)
1 => string '/js/dfg4dg.js' (length=13)
2 => string '/js/fg8hfhrt.js' (length=15)
2 => string '/js/yjtdygj.js' (length=14)
2 => string '/js/2q5g54rvfd.js' (length=17)
*/
$json = json_encode($data);
$gz = gzdeflate($json, 9);
$base64 = base64_encode($gz);
$paths = urlencode($base64);
// outputs: i1aK0c8qjtFPyUhJyjW3yEhJS9LLKlbSgQmnpZukpCOLpKVbZKRlFJUgi1VmlaRUpmchCxkVmqabmhSVpaWARGMB
Not very impressive and pretty slow, I think there should be a better way of doing this...
Question
What would be the best approach to this problem? How can we present the smallest string possible?
PS
It's not the biggest issue if it's slow but it's a variable to be considered. The array will be hashed and retrived from cache when possible.