Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

GithubStars
in package

FinalYes

GitHub stargazer-count cache.

Renders directly into HTML (no client-side fetch, no empty span / number flicker). Shared across workers via a 1-row OpenSwoole Store table; refreshed asynchronously via a background coroutine when stale, so requests are never blocked on the remote GitHub call.

Usage:

In app.php boot, before $app->run():

\ZealPHP\GithubStars::register('sibidharan/zealphp');

In templates / route handlers:

<span>★ <?= htmlspecialchars(\ZealPHP\GithubStars::format()) ?></span>

Table of Contents

Constants

FETCH_TIMEOUT  : mixed = 2.0
GitHub API timeout — bounded so a slow upstream can't stall a worker.
TABLE  : mixed = 'github_stars'
TTL_SECONDS  : mixed = 900
Cache TTL — refresh the value at most once per N seconds.

Properties

$refreshInFlight  : bool
True when a refresh coroutine is currently in flight (per worker).
$repo  : string|null
"owner/repo" — set by register(), read by the refresher.

Methods

format()  : string
Render-time accessor. Returns the cached formatted count immediately, and triggers a background refresh if the cache is stale or empty.
register()  : void
Create the shared Store table. Call ONCE before $app->run().
fetchAndStore()  : void
formatCount()  : string
"k"-suffixed formatting that matches the previous client-side script.
refreshAsync()  : void
Spawn a coroutine to refresh the cache. Idempotent — at most one in-flight refresh per worker at a time (the per-worker flag guards against thundering-herd on cold starts).

Constants

FETCH_TIMEOUT

GitHub API timeout — bounded so a slow upstream can't stall a worker.

private mixed FETCH_TIMEOUT = 2.0

TTL_SECONDS

Cache TTL — refresh the value at most once per N seconds.

private mixed TTL_SECONDS = 900

Properties

$refreshInFlight

True when a refresh coroutine is currently in flight (per worker).

private static bool $refreshInFlight = false

$repo

"owner/repo" — set by register(), read by the refresher.

private static string|null $repo = null

Methods

format()

Render-time accessor. Returns the cached formatted count immediately, and triggers a background refresh if the cache is stale or empty.

public static format() : string

Returns an empty string before the first successful fetch (template should handle that gracefully — e.g. hide the span when empty).

Return values
string

register()

Create the shared Store table. Call ONCE before $app->run().

public static register(string $repo) : void

The repo argument selects which github.com/owner/repo to track.

Parameters
$repo : string

fetchAndStore()

private static fetchAndStore(string $repo) : void
Parameters
$repo : string

formatCount()

"k"-suffixed formatting that matches the previous client-side script.

private static formatCount(int $n) : string

999"999"; 1234"1.2k"; 12345"12k".

Parameters
$n : int
Return values
string

refreshAsync()

Spawn a coroutine to refresh the cache. Idempotent — at most one in-flight refresh per worker at a time (the per-worker flag guards against thundering-herd on cold starts).

private static refreshAsync() : void
On this page