使用 WPS APK 中的 OBJECTS 在 FOREACH 循环中分页

Pagination in FOREACH loop with OBJECTS from WPS APK

我编写的这段代码运行良好,它从 s3 存储桶中的嵌套文件夹中检索随登录用户更改而更改的文件,使用根文件夹在嵌套文件夹中提供来自 jpg 的图像以创建 DIV ,并打印出从存储在与图像相同的文件夹中的 CSV 中获取的信息。

$current_user = wp_get_current_user();  
$current_user_nambre = $current_user->user_login;
$dir = 's3://xy/zvx/users/' . $current_user_nambre . '/';

$s3 = new S3Client([
    'region' => 'eu-central-1',
    'profile' => 'default',
    'version' => '1'
]);

$s3->registerStreamWrapper();
$products = new RecursiveDirectoryIterator($dir);
$medias = new RecursiveDirectoryIterator($is_product);
                    foreach ($medias as $is_thumb) 
                    {[...]

它有效,而且完美。但是......如果它发现太多 CSV,FirstByte 花费的时间太长,服务器会自动退出请求,给用户一个超时页面。

我想做的是在 FOREACH 中使用分页,但它指出我不能对对象使用 array_slice...

我使用 LimitIterator 管理它工作,它工作得很好。

$products = new RecursiveDirectoryIterator($dir);
$limitIterator = new LimitIterator($products, $offset, $limit);
$n = 0;
foreach ($limitIterator as $is_product) {
[...]


[...] }
if ($n == 10) {
    echo '<a href="?offset='.($offset + 10).'">Next</a>';

如在 Whosebughere 上所见