For reason that I’ll not discuss here, I’m forced to parse a large directory of files (we are talking 100.000 < x < 1.000.000+) and return the filelist as an array.
I’m already caching the file list, the problem is array_slice.
Yes, because there is a catch, this list of file must be “paginated” returning them in block of 16.
What I’m doing is this:
$items_per_page = 16;
$offset = ($current_page * $items_per_page) + $items_per_page;
array_slice($array,-$offset,$items_per_page);
It’s easy to see that in a few pages we’ll have huge offsets.
Also starting from page four (offset = -80) there is a huge performance hit.
What could I use instead of array_slice to achieve this sort of array pagination?
Thanks
If the array is numerically indexed (without skipping numbers) you could try to use a for loop.
Edit:
I just did some benchmarking to get an idea. On our server, with an array of 1 million items, processed 100 times each, array_slice() took 2.5689ms to process. Using a for loop took 0.0031ms.