PHPackages                             grebennik/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. grebennik/ip-clock

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

grebennik/ip-clock
==================

A PSR-20 Clock implementation that returns time based on server external IP address using external API.

01PHP

Since Feb 24Pushed 4mo agoCompare

[ Source](https://github.com/Grebennik/ip-clock)[ Packagist](https://packagist.org/packages/grebennik/ip-clock)[ RSS](/packages/grebennik-ip-clock/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

IP Clock (PSR-20)
=================

[](#ip-clock-psr-20)

A Composer package that returns accurate time and timezone based on a server’s external IP address. Implements `\Psr\Clock\ClockInterface` (PSR-20).

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

[](#requirements)

- PHP 8.2 or higher
- Composer

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

[](#installation)

Install the package via Composer:

```
composer require grebennik/ip-clock
```

*Note: If the package is not yet published on Packagist, add a VCS repository to your `composer.json`:*

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

Usage
-----

[](#usage)

### Automatically use the server’s external IP

[](#automatically-use-the-servers-external-ip)

```
use Grebennik\IpClock\IpClock;

$clock = new IpClock();
$now = $clock->now(); // Returns DateTimeImmutable

echo $now->format('Y-m-d H:i:s P');
```

### Use a specific IP address

[](#use-a-specific-ip-address)

```
use Grebennik\IpClock\IpClock;

$clock = new IpClock('8.8.8.8');
$now = $clock->now();

echo "Time for 8.8.8.8: " . $now->format('H:i:s');
```

Data source
-----------

[](#data-source)

By default, the package uses [WorldTimeAPI](http://worldtimeapi.org/). This service is free and does not require an API key.

### Using Authenticated APIs (API Keys)

[](#using-authenticated-apis-api-keys)

Many commercial time/IP services (like IpStack, AbstractAPI, etc.) require an API key. You can provide it in two ways depending on the API requirements:

#### Option 1: Via Headers (Recommended)

[](#option-1-via-headers-recommended)

If the service expects the key in a header (e.g., `X-API-Key` or `Authorization`), pass a pre-configured Guzzle client:

```
use Grebennik\IpClock\IpClock;
use GuzzleHttp\Client;

$client = new Client([
    'headers' => [
        'X-API-Key' => 'your_secret_key_here'
    ]
]);

$clock = new IpClock(httpClient: $client, apiUrl: 'https://api.example.com/time');
```

#### Option 2: Via Query Parameters

[](#option-2-via-query-parameters)

If the key must be in the URL, use the `{ip}` placeholder to define where the IP address should be inserted:

```
use Grebennik\IpClock\IpClock;

// The {ip} placeholder will be replaced with the actual IP address
$apiUrl = 'https://api.example.com/time?key=your_secret_key&ip={ip}';

$clock = new IpClock(
    ip: '8.8.8.8',
    apiUrl: $apiUrl,
    parser: new MyCustomParser()
);
```

### Custom API and Response Parsing

[](#custom-api-and-response-parsing)

If you use a different API that returns data in a different format, you can implement `ResponseParserInterface` and pass it to the constructor:

```
use Grebennik\IpClock\IpClock;
use Grebennik\IpClock\ResponseParserInterface;
use DateTimeImmutable;

class MyCustomParser implements ResponseParserInterface
{
    public function parse(array $data): DateTimeImmutable
    {
        // Your logic to extract time from $data
        return new DateTimeImmutable($data['custom_time_field']);
    }
}

$clock = new IpClock(
    apiUrl: 'https://my-custom-api.com/time',
    parser: new MyCustomParser()
);
```

You can also inject your own HTTP client (Guzzle or any `Psr\Http\Client\ClientInterface`) via the constructor.

Testing
-------

[](#testing)

Run tests with:

```
vendor/bin/phpunit tests
```

License
-------

[](#license)

MIT

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance52

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/637ad8051af6500dee8431bc167f46c6802e03aa99f540cc0af185c316f90a42?d=identicon)[Grebennik](/maintainers/Grebennik)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[mehedijaman/laravel-zkteco

Connect any zkteco fingerprint attendance machine to laravel application with no effort.

524.9k](/packages/mehedijaman-laravel-zkteco)

PHPackages © 2026

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