Skip to content

feat: Add configurable flush interval#171

Merged
marandaneto merged 6 commits into
mainfrom
feat/add-flush-interval
Jun 18, 2026
Merged

feat: Add configurable flush interval#171
marandaneto merged 6 commits into
mainfrom
feat/add-flush-interval

Conversation

@marandaneto

@marandaneto marandaneto commented Jun 17, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

PHP batching previously flushed queued events only when batch_size was reached, via explicit flush(), or during cleanup. This adds a configurable flush interval mechanism for low-volume queues while accounting for PHP's lack of a portable in-process background timer.

💚 How did you test it?

  • php -l lib/QueueConsumer.php && php -l lib/Client.php && php -l lib/PostHog.php && php -l test/PostHogTest.php
  • ./vendor/bin/phpunit test/PostHogTest.php --filter 'FlushInterval|testInvalidCaptureFlushIntervalDefaultsToFiveSeconds' --no-coverage
  • php scripts/check-public-api.php
  • git diff --check
  • ! rg -n 'flush_interval_ms|"flush_interval"|flush_interval\?:' lib test README.md composer.json
  • ./vendor/bin/phpunit --no-coverage — passes with existing warnings/deprecations

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with Pi coding agent assistance. The change keeps the public API minimal with only flush_interval_seconds, defaults to 5 seconds, treats invalid, negative, or non-finite values as the default, flushes immediately when set to 0, and uses opportunistic interval flushing on the next enqueue because PHP does not provide a portable request-local background timer. Follow-up review feedback clarified the existing timeout and maximum_backoff_duration units in PHPDoc without renaming those options.

@marandaneto marandaneto self-assigned this Jun 17, 2026
@greptile-apps

greptile-apps Bot commented Jun 17, 2026

Copy link
Copy Markdown
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
test/PostHogTest.php:551-631
**Duplicate tests should be a single parameterised test**

`testNegativeCaptureFlushIntervalDefaultsToFiveSeconds` and `testInvalidCaptureFlushIntervalDefaultsToFiveSeconds` are byte-for-byte identical except for the value of `flush_interval_seconds` (`-1` vs `"1"`). The project rule says to prefer parameterised tests and to say everything OnceAndOnlyOnce. A single `@dataProvider` method covering both invalid inputs would satisfy both rules and make it trivial to add further edge cases (e.g. `NAN`, `INF`, `null`) without another copy-paste block.

Reviews (1): Last reviewed commit: "feat: add configurable flush interval" | Re-trigger Greptile

Comment thread test/PostHogTest.php
@marandaneto

Copy link
Copy Markdown
Member Author

#170 would be the ideal word but its much more effort

@marandaneto marandaneto marked this pull request as ready for review June 17, 2026 15:16
@marandaneto marandaneto requested a review from a team as a code owner June 17, 2026 15:16
@greptile-apps

greptile-apps Bot commented Jun 17, 2026

Copy link
Copy Markdown

Reviews (2): Last reviewed commit: "test: parameterize invalid flush interva..." | Re-trigger Greptile

Comment thread lib/Client.php
@marandaneto marandaneto merged commit 3ff0479 into main Jun 18, 2026
20 checks passed
@marandaneto marandaneto deleted the feat/add-flush-interval branch June 18, 2026 11:53
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.

2 participants