PHPackages                             dmkravchuk/ip-clock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dmkravchuk/ip-clock

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dmkravchuk/ip-clock
===================

Resolves accurate server time and timezone via external IP lookup

v1.0.0(3mo ago)02MITPHPPHP ^8.2CI passing

Since Mar 10Pushed 3mo agoCompare

[ Source](https://github.com/dmkravchuk/ip-clock)[ Packagist](https://packagist.org/packages/dmkravchuk/ip-clock)[ RSS](/packages/dmkravchuk-ip-clock/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

dmkravchuk/ip-clock
===================

[](#dmkravchukip-clock)

A PSR-20 compliant Composer package that returns the correct server time and timezone based on the server's external IP address.

Requirements
------------

[](#requirements)

- PHP ^8.2
- Composer

Installation
------------

[](#installation)

### Via Packagist

[](#via-packagist)

```
composer require dmkravchuk/ip-clock
```

### Via VCS (without Packagist)

[](#via-vcs-without-packagist)

Add to your `composer.json`:

```
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/dmkravchuk/ip-clock"
    }
]
```

Then run:

```
composer require dmkravchuk/ip-clock
```

Configuration
-------------

[](#configuration)

One of the time providers — [ipgeolocation.io](https://ipgeolocation.io) — requires a free API key.

1. Create a free account at
2. Check the Dashboard the API KEY section
3. Copy your API key
4. Set it as an environment variable in `.env` file:

```
IPGEOLOCATION_API_KEY=your_api_key_here

```

> The package works without this key — ipgeolocation.io will simply be skipped if the key is not set.

Usage
-----

[](#usage)

### Basic usage (auto-detect server IP)

[](#basic-usage-auto-detect-server-ip)

```
use DmKravchuk\IpClock\ClockFactory;

$clock = ClockFactory::create();
$now = $clock->now();

echo $now->format('Y-m-d H:i:s'); // 2026-03-10 14:00:00
echo $now->getTimezone()->getName(); // Europe/Kyiv
```

### With explicit IP address

[](#with-explicit-ip-address)

```
$clock = ClockFactory::create(ip: '8.8.8.8');
$now = $clock->now();

echo $now->getTimezone()->getName(); // America/Los_Angeles
```

### With custom PSR-3 logger

[](#with-custom-psr-3-logger)

```
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('ip-clock');
$logger->pushHandler(new StreamHandler('php://stdout'));

$clock = ClockFactory::create(logger: $logger);
```

### PSR-20 compatibility

[](#psr-20-compatibility)

```
use Psr\Clock\ClockInterface;

function doSomething(ClockInterface $clock): void
{
    $now = $clock->now();
}

doSomething(ClockFactory::create());
```

How it works
------------

[](#how-it-works)

1. Resolves the server's external IP via [ipify.org](https://ipify.org)
2. Determines the timezone using a chain of time providers:
    - **Primary:** [timeapi.io](https://timeapi.io) — free, no API key required
    - **Fallback #1:** [worldtimeapi.org](https://worldtimeapi.org) — free, no API key required
    - **Fallback #2:** [ipgeolocation.io](https://ipgeolocation.io) — free API key required
3. If all providers fail — returns current time in **UTC**

Running tests
-------------

[](#running-tests)

```
composer test
```

License
-------

[](#license)

MIT

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance80

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

105d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e79f6b390fcea7467c52d484dd2288d2036b231852bd222e1feeffa3766ced6?d=identicon)[dmkravchuk](/maintainers/dmkravchuk)

---

Top Contributors

[![dmkravchuk](https://avatars.githubusercontent.com/u/7489674?v=4)](https://github.com/dmkravchuk "dmkravchuk (15 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dmkravchuk-ip-clock/health.svg)

```
[![Health](https://phpackages.com/badges/dmkravchuk-ip-clock/health.svg)](https://phpackages.com/packages/dmkravchuk-ip-clock)
```

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[symfony/symfony

The Symfony PHP framework

31.4k86.9M2.2k](/packages/symfony-symfony)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

562565.8k42](/packages/ecotone-ecotone)[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.8k69.4k](/packages/grumpydictator-firefly-iii)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

749284.3k35](/packages/civicrm-civicrm-core)[web-auth/webauthn-lib

FIDO2/Webauthn Support For PHP

1237.8M120](/packages/web-auth-webauthn-lib)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
