Download the PHP package alex-no/server-time-clock without Composer
On this page you can find all versions of the php package alex-no/server-time-clock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alex-no/server-time-clock
More information about alex-no/server-time-clock
Files in alex-no/server-time-clock
Package server-time-clock
Short Description PSR-20 clock implementation that returns the current server time based on its local timezone.
License MIT
Homepage https://github.com/alex-no/server-time-clock
Informations about the package server-time-clock
Server Time Clock
PSR-20 clock implementation that returns the current server time based on its local timezone or online providers.
Installation
Install via Composer:
Usage
Configuration Options
| Key | Type | Description |
|---|---|---|
client |
string | Preferred time provider (WorldTimeApi, IpGeoLocation, etc.) |
credentials |
array | API keys for time providers (optional) |
enable_cache |
bool | Enable APCu-based caching (default: false) |
cache_ttl |
int | Cache duration in seconds |
useMock |
bool | Enable/Disable Mock for tests (default: false) |
Providers
🌐 WorldTimeApi – no key required
🌐 IpGeoLocation – requires free API key from ipgeolocation.io
🌐 TimeApiIo – no key required
Laravel Integration
You can integrate this package into Laravel with minimal setup.
Configuration (Optional)
To publish the config file:
This will create config/server-clock.php:
Usage in Laravel
Yii2 Integration
Configuration
You may use the ServerClock class directly or configure it as a Yii2 component:
Usage
Then use it:
Note: Yii2 support is optional and requires yiisoft/yii2 to be installed in your project.
Optional Dependencies
This package is framework-agnostic. Laravel and Yii2 integrations are provided for convenience.
| Framework | Package | Required? |
|---|---|---|
| Laravel | laravel/framework |
Optional |
| Yii2 | yiisoft/yii2 |
Optional |
APCu Cache Requirements
If you enable caching (enable_cache => true), make sure the APCu extension is installed and enabled in your PHP configuration. This typically means:
- The apcu extension must be installed (e.g., via pecl install apcu or appropriate package manager).
- For CLI usage (e.g., when running tests), ensure apc.enable_cli=1 is set in your php.ini.
You can verify if APCu is available by running:
Testing
Run PHPUnit tests:
License
MIT License
Made with ❤️ by Oleksandr Nosov