Skip to content

Improved: lowered timeout and connect_timeout to 10 and 5 seconds.#290

Merged
Dan0sz merged 3 commits intodevelopfrom
lower_timeout
Mar 25, 2026
Merged

Improved: lowered timeout and connect_timeout to 10 and 5 seconds.#290
Dan0sz merged 3 commits intodevelopfrom
lower_timeout

Conversation

@Dan0sz
Copy link
Collaborator

@Dan0sz Dan0sz commented Mar 25, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Added explicit network timeouts to API requests (default: 10s request timeout, 5s connection timeout).
  • Documentation

    • Documented two new plugin filters to configure API request and connection timeouts.
  • Chores

    • Clarified and cleaned up PHPDoc and README wording for consistency.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 25, 2026

Warning

Rate limit exceeded

@Dan0sz has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cebd2941-1f6b-48fc-893d-02db5c6ee75f

📥 Commits

Reviewing files that changed from the base of the PR and between 56ec7a9 and cd80d27.

📒 Files selected for processing (1)
  • README.md
📝 Walkthrough

Walkthrough

Client now reads WordPress filters plausible_analytics_api_timeout and plausible_analytics_api_connect_timeout (defaults 10.0 and 5.0) and uses them to configure GuzzleClient timeout and connect_timeout in the constructor. README filters documentation was added; PHPDoc formatting was adjusted only.

Changes

Cohort / File(s) Summary
Client / HTTP timeouts
src/Client.php
Constructor now applies plausible_analytics_api_timeout and plausible_analytics_api_connect_timeout (defaults 10.0 / 5.0) to GuzzleClient timeout and connect_timeout. PHPDoc punctuation and parameter annotation formatting updated. No public signatures changed.
Documentation: filters
README.md
Added documentation entries for plausible_analytics_api_timeout and plausible_analytics_api_connect_timeout under Filters.

Sequence Diagram(s)

sequenceDiagram
    participant WP as WordPress (filters)
    participant Client as Client::__construct
    participant Guzzle as GuzzleClient

    WP->>Client: provide `plausible_analytics_api_connect_timeout` (default 5.0)
    WP->>Client: provide `plausible_analytics_api_timeout` (default 10.0)
    Client->>Guzzle: instantiate with { connect_timeout: 5.0, timeout: 10.0 }
    Guzzle-->>Client: configured HTTP client returned
Loading

Poem

🐰 A timeout's tick, a timeout's tock,
Five seconds to connect, ten to talk,
Filters whisper values bright,
The client hops and sets them right,
Small changes, steady flight!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Improved: lowered timeout and connect_timeout to 10 and 5 seconds' clearly and concisely summarizes the main change: configuring HTTP timeouts with specific values (10s and 5s) via new WordPress filters in the Plausible Analytics plugin.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch lower_timeout

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/Client.php (1)

43-43: Make timeout values filterable instead of hardcoded.

Line 43 hardcodes network limits globally. Consider exposing these via WP filters so slower environments can tune values without code edits.

Diff suggestion
-		$this->api_instance = new DefaultApi( new GuzzleClient( [ 'timeout' => 10, 'connect_timeout' => 5 ] ), $config );
+		$timeout         = (float) apply_filters( 'plausible_analytics_http_timeout', 10.0 );
+		$connect_timeout = (float) apply_filters( 'plausible_analytics_http_connect_timeout', 5.0 );
+		$this->api_instance = new DefaultApi(
+			new GuzzleClient(
+				[
+					'timeout'         => $timeout,
+					'connect_timeout' => $connect_timeout,
+				]
+			),
+			$config
+		);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Client.php` at line 43, The hardcoded timeouts passed to the GuzzleClient
in the Client class (where DefaultApi is instantiated) should be exposed via WP
filters so environments can override them; replace the literal 10 and 5 with
calls to apply_filters (e.g. apply_filters('your_plugin_api_timeout', 10) and
apply_filters('your_plugin_connect_timeout', 5)), cast the results to int/float
as needed, and use those filtered values when constructing the new GuzzleClient
in the Client.php constructor where DefaultApi is created.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/Client.php`:
- Line 43: The hardcoded timeouts passed to the GuzzleClient in the Client class
(where DefaultApi is instantiated) should be exposed via WP filters so
environments can override them; replace the literal 10 and 5 with calls to
apply_filters (e.g. apply_filters('your_plugin_api_timeout', 10) and
apply_filters('your_plugin_connect_timeout', 5)), cast the results to int/float
as needed, and use those filtered values when constructing the new GuzzleClient
in the Client.php constructor where DefaultApi is created.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6a1b28b8-cfb2-4d30-938c-0d0a65cbc73c

📥 Commits

Reviewing files that changed from the base of the PR and between 6a29e39 and dd2ff84.

📒 Files selected for processing (1)
  • src/Client.php

@codecov
Copy link

codecov bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Client.php`:
- Around line 43-45: The filtered timeout values can end up as 0.0 if
non-numeric input is returned; before passing to DefaultApi/GuzzleClient
normalize $timeout and $connect_timeout by validating and coercing them to
positive numbers and falling back to the intended defaults (10.0 and 5.0).
Specifically, after calling apply_filters('plausible_analytics_api_timeout',
10.0) and apply_filters('plausible_analytics_api_connect_timeout', 5.0) validate
the results (e.g., is_numeric and greater than 0) and assign the default if not,
then use the sanitized $timeout and $connect_timeout when constructing new
GuzzleClient and DefaultApi.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 63c95eb0-429b-40bb-9a4a-bb952c2716d1

📥 Commits

Reviewing files that changed from the base of the PR and between dd2ff84 and 56ec7a9.

📒 Files selected for processing (2)
  • README.md
  • src/Client.php
✅ Files skipped from review due to trivial changes (1)
  • README.md

@Dan0sz Dan0sz merged commit 850407c into develop Mar 25, 2026
7 checks passed
@Dan0sz Dan0sz deleted the lower_timeout branch March 25, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant