PHPackages                             vladyslav-dyba/server-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. vladyslav-dyba/server-clock

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

vladyslav-dyba/server-clock
===========================

Provide correct server time based on its external IP

1.2(1y ago)111PHPPHP ^8.1

Since Apr 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/DybaVladyslav/server-clock)[ Packagist](https://packagist.org/packages/vladyslav-dyba/server-clock)[ RSS](/packages/vladyslav-dyba-server-clock/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

ServerClock package
===================

[](#serverclock-package)

[![Packagist](https://camo.githubusercontent.com/a638dd59f77301db8fa982959cb7d23d63fa07f31475842e499ce1de7ae6a77f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796f75722d76656e646f722f7061636b6167652d6e616d652e737667)](https://packagist.org/packages/your-vendor/package-name)

Provide correct server time based on its external IP

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [TestRun](#test-run)
- [Usage](#usage)
- [Structure](#structure)
- [Configuration](#configuration)

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

[](#installation)

### Composer Installation

[](#composer-installation)

To install the package, you can use Composer:

```
composer require vladyslav-dyba/server-clock
```

This will add the package to your composer.json file and download it into the vendor directory. Manual Installation

In case you want to include it manually, you can also follow these steps:

```
 - Download the package files.
 - Include the Composer autoloader in your project:

```

```
require 'vendor/autoload.php';
```

Test run
--------

[](#test-run)

Once you clone the package sepparetly, you can perform a test run to get local time based on an IP

To get local time for specific IP

```
  php ./bin/console.php 8.8.8.8
  php ./vendor/vladyslav-dyba/server-clock/bin/console.php 8.8.8.8
```

To get local time for external server IP

```
  php ./bin/console.php
  php ./vendor/vladyslav-dyba/server-clock/bin/console.php
```

Usage
-----

[](#usage)

Here, explain how to use your package with practical examples. Provide some basic functionality and advanced use cases.

To get a local time of the external server IP:

```
// Include the Composer autoloader
require 'vendor/autoload.php';

// IpSource object provides an IP for the next steps
$ipSource = new ExternalIpSource(IpInfoDataProviderFactory::make());

// Source of time
// Current example works based on defined IP
// Though, a client of the library can use its own implementation for TimeSourceDataProviderInterface
$timeSource = new DefaultTimeSource(TimeApiDataProviderFactory::make($ipSource));

// ServerClock is the core of the library
// It provides time based on TimeSourceInterface
// As well, a client of the library can use its own implementation for TimeSourceInterface

$serverClock = new ServerClock($timeSource);
$time = $serverClock->now();

echo $time->format(DateTime::ATOM) . "\n";
```

To get a local time of the provided a specific IP:

```
// Include the Composer autoloader
require 'vendor/autoload.php';

// Receiving a specific IP
$ip = $argv[1];

// IpSource object provides an IP for the next steps
$ipSource = new CustomIpSource($ip);

// Source of time
// Current example works based on defined IP
// Though, a client of the library can use its own implementation for TimeSourceDataProviderInterface
$timeSource = new DefaultTimeSource(TimeApiDataProviderFactory::make($ipSource));

// ServerClock is the core of the library
// It provides time based on TimeSourceInterface
// As well, a client of the library can use its own implementation for TimeSourceInterface

$serverClock = new ServerClock($timeSource);
$time = $serverClock->now();

echo $time->format(DateTime::ATOM) . "\n";
```

Structure
---------

[](#structure)

### Core

[](#core)

The core of the package is `ServerClock` object that implements `TimeSourceInterface` interface

### TimeSource

[](#timesource)

`ServerClock` gets a time from a `$timeSource` that implements `TimeSourceInterface`

Package has only one basic implementation of the `TimeSourceInterface` - `DefaultTimeSource`and its TimeSourse DataProvider: [TimeApi](https://timeapi.io) service

Client can substitute the DataProvider with their own solution that implements the `TimeSourceInterface`

### IpSource

[](#ipsource)

Since `TimeSource` works based on an IP information, `IpSourceInterface` implementation has to be provided.

Package has two basic implementation of the `IpSourceInterface`:

- `CustomIpSource` - provides any specific IP address
- `ExternalIpSource` - uses [IpInfo](https://ipinfo.io/) service as IpSource DataProvider to get and provide the external server IP

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

[](#configuration)

Regardless, the package has its own `TimeSourceInterface` and `IpSourceInterface` implementations,

there is no any configuration that can be applied for the package because the package was created with minimum dependencies and its the primary approach to configure the package is substituting the interfaces implementations on a client side

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance47

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

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

394d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/566aa9c0668604e77801bc772e1bf0a78b75e4dae8a130adc4098bc52ef3efc3?d=identicon)[DybaVladyslav](/maintainers/DybaVladyslav)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vladyslav-dyba-server-clock/health.svg)

```
[![Health](https://phpackages.com/badges/vladyslav-dyba-server-clock/health.svg)](https://phpackages.com/packages/vladyslav-dyba-server-clock)
```

###  Alternatives

[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[dhlparcel/magento2-plugin

DHL Parcel plugin for Magento 2

11180.5k2](/packages/dhlparcel-magento2-plugin)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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