and in advance for help.
Background - I am writing a PHP script that should figure out where the recipient is going. Telephony prefixes are strings that determine the purpose. For each call, the program must find the longest prefix corresponding to the line. For example, the number 30561234567 would correspond to 305, but not 3057 or 304. If 3056 existed, this would be the preferred match.
After exploring several data structures, the tree in which each node stores a digit and contains pointers to the other 10 possible options seems ideal. This can be implemented as an array of arrays, where the script can check 3, find the array there, then check 0 on this new array, find another array, and so on, until it finds a value instead of an array. This value will be the destination identifier (script output).
Requirements - Performance is absolutely important. The time taken to verify these prefixes delays the call, and each server must handle large numbers of calls, so the data structure must be stored in memory. There are currently about 6,000 prefixes.
Problem - the script is run every time the server accepts the call, so the data must be stored in some cache server. After checking memcached and APC (Advanced PHP Cache) I decided to use APC because it is [much faster] [3] (this is local memory)
The problem is that an array of arrays can have up to 10 arrays in depth and will be a very complex data structure, which, if I add to the cache as an object, will take a long time to de-serialize.
However, if I add each separate array to the cache separately (with some logical naming structure so that it can easily find it as 3 for array 3, then 30 for array 30, 305 for the array following this patch, etc. ) I will have to take different arrays from the cache many times (up to 10 per call), which changes the cache too often.
Am I going to do it right? Maybe there is another solution? Or one of the methods that I suggested above the other?
Thank you for entering
Alex
performance php caching asterisk
Alex Recarey
source share