You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GCP Stackdriver Logging API分页问题:pageSize在PHP API中未生效

Stackdriver Logging API PHP Client pageSize Not Paging (Returns All Entries)

Hey, I’ve run into this exact issue with the GCP Logging PHP SDK before—pageSize works perfectly in the API console but seems ignored when using the PHP client. Let’s break down the common causes and fixes:

1. You’re Accidentally Fetching All Pages (Iterator to Array Pitfall)

The listEntries() method returns a ItemIterator that lazily loads pages of results. If you’re using iterator_to_array($entries) to convert it to an array, the SDK will automatically loop through all pages and fetch every entry, making it look like pagination isn’t working.

Instead, to get just the first page (and the next page token), use the iterator’s built-in methods:

use Google\Cloud\Logging\LoggingClient;

$logging = new LoggingClient();

// Fetch first page with pageSize=100
$entriesIterator = $logging->listEntries([
    'projectIds' => ['YOUR_PROJECT_ID'],
    'resourceNames' => ['YOUR_RESOURCE_NAME'],
    'filter' => 'YOUR_FILTER',
    'orderBy' => 'timestamp desc',
    'pageSize' => 100
]);

// Get only the entries from the current (first) page
$firstPageEntries = $entriesIterator->currentPage();

// Grab the token for the next page
$nextPageToken = $entriesIterator->nextPageToken();

// To fetch the next page, pass the token in your next request
$nextPageIterator = $logging->listEntries([
    'pageSize' => 100,
    'pageToken' => $nextPageToken,
    // Include other parameters (projectIds, filter, etc.) again
]);

2. Verify Parameter Spelling & Placement

Double-check that you’re passing pageSize (camelCase) correctly in the options array passed to listEntries(). The PHP SDK expects camelCase for API parameters, not snake_case.

Avoid passing it as a separate function argument—make sure it’s part of the associative array of options.

3. Update Your Google Cloud PHP SDK

Older versions of the google/cloud-logging package had bugs related to pagination handling. Run this command to update to the latest stable version:

composer update google/cloud-logging

4. Debug the Actual API Request

To confirm if pageSize is being sent to the API, enable debug mode when initializing the LoggingClient. This will print the full HTTP request details, so you can verify the parameter is included in the request body:

$logging = new LoggingClient([
    'debug' => true
]);

Look for the pageSize field in the POST body sent to the logging API endpoint—it should match your set value (100).


内容的提问来源于stack exchange,提问作者Markus Mikely

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:05:39