Problem:
- We need to serialize the array into a short string, the shorter the better.
- Importance is reflected more in a larger array than in a smaller one.
- The string will be used in the request for receipt, so it must be decrypted.
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 rather slow, I think there should be a better way to do this ...
Question
What would be the best approach to this problem? How can we represent the smallest line?
PS
This is not the biggest problem if it is slow, but it is a variable that needs to be considered. The array will be hashed and retrieved from the cache whenever possible.
source
share