PHPackages                             tomkyle/kurzelinks - 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. tomkyle/kurzelinks

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

tomkyle/kurzelinks
==================

Link shortener using the kurzelinks.de API. Supports PSR-6 caches and rate limits.

1.1.2(11mo ago)05MITPHPPHP ^8.3CI passing

Since Aug 28Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/tomkyle/KurzeLinks)[ Packagist](https://packagist.org/packages/tomkyle/kurzelinks)[ RSS](/packages/tomkyle-kurzelinks/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (6)Used By (0)

tomkyle/kurzelinks
==================

[](#tomkylekurzelinks)

**tomkyle/kurzelinks** is a PHP library designed to create short links using the [kurzelinks.de](https://kurzelinks.de) service. This library provides different implementations of the `KurzeLinksInterface` to allow developers to integrate and extend the short link creation functionality with ease.

[![Packagist](https://camo.githubusercontent.com/74be10b720c0232ae59e54257242d90e6e3dd2395ebb730829406468d72129fc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f6d6b796c652f6b75727a656c696e6b732e7376673f7374796c653d666c6174)](https://packagist.org/packages/tomkyle/kurzelinks)[![PHP version](https://camo.githubusercontent.com/391b8b2aa4c5046f74cea293240adf8414936d60814ef4f9131eef1a23e21d8f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f6d6b796c652f6b75727a656c696e6b732e737667)](https://packagist.org/packages/tomkyle/kurzelinks)[![Tests](https://github.com/tomkyle/KurzeLinks/actions/workflows/php.yml/badge.svg)](https://github.com/tomkyle/KurzeLinks/actions/workflows/php.yml)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)

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

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [GuzzleKurzeLinks](#guzzlekurzelinks)
    - [Psr18KurzeLinks](#psr18kurzelinks)
    - [RateLimitKurzeLinks](#ratelimitkurzelinks)
    - [Psr6CacheKurzeLinks](#psr6cachekurzelinks)
    - [PassthroughKurzeLinks](#passthroughkurzelinks)
    - [CallableKurzeLinks](#callablekurzelinks)
- [Best Practice: Usage Recommendation](#best-practice-usage-recommendation)
- [Interface](#interface)
    - [KurzeLinksInterface](#kurzelinksinterface)

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

[](#installation)

You can install this library via Composer:

```
composer require tomkyle/kurzelinks
```

Usage
-----

[](#usage)

### GuzzleKurzeLinks

[](#guzzlekurzelinks)

The `GuzzleKurzeLinks` class is an implementation of `KurzeLinksInterface` that uses GuzzleHTTP to interact with the [KurzeLinks.de API.](https://kurzelinks.de/kurz-url-api)

#### Example

[](#example)

```
use tomkyle\KurzeLinks\GuzzleKurzeLinks;

$api = 'https://kurzelinks.de/api';
$key = 'your_api_key';
$kurzeLinks = new GuzzleKurzeLinks($api, $key);

$shortUrl = $kurzeLinks->create('https://example.com');
echo $shortUrl;  // Outputs the shortened URL
```

### Psr18KurzeLinks

[](#psr18kurzelinks)

The `Psr18KurzeLinks` class is an implementation of `KurzeLinksInterface` that uses a PSR-18 compliant HTTP client to interact with the [KurzeLinks.de API.](https://kurzelinks.de/kurz-url-api)

#### Example

[](#example-1)

```
use tomkyle\KurzeLinks\Psr18KurzeLinks;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;

$api = 'https://kurzelinks.de/api';
$key = 'your_api_key';

// Assume you have a PSR-18 compliant HTTP client,
// and PSR-17 request and stream factories
$httpClient = new YourPsr18Client();
$requestFactory = new YourRequestFactory();
$streamFactory = new YourStreamFactory();

$kurzeLinks = new Psr18KurzeLinks($api, $key, $httpClient, $requestFactory, $streamFactory);

$shortUrl = $kurzeLinks->create('https://example.com');
echo $shortUrl;  // Outputs the shortened URL
```

### RateLimitKurzeLinks

[](#ratelimitkurzelinks)

The `RateLimitKurzeLinks` class is a decorator for any `KurzeLinksInterface` implementation. It introduces a rate limit by pausing execution between requests.

#### Example

[](#example-2)

```
use tomkyle\KurzeLinks\Psr18KurzeLinks;
use tomkyle\KurzeLinks\RateLimitKurzeLinks;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;

$api = 'https://kurzelinks.de/api';
$key = 'your_api_key';

// Assume you have a PSR-18 compliant HTTP client, request factory, and stream factory
$httpClient = new YourPsr18Client();
$requestFactory = new YourRequestFactory();
$streamFactory = new YourStreamFactory();

$innerKurzeLinks = new Psr18KurzeLinks($api, $key, $httpClient, $requestFactory, $streamFactory);
$rateLimitedKurzeLinks = new RateLimitKurzeLinks($innerKurzeLinks, 4000); // 4000ms sleep

$shortUrl = $rateLimitedKurzeLinks->create('https://example.com');
echo $shortUrl;  // Outputs the shortened URL
```

### Psr6CacheKurzeLinks

[](#psr6cachekurzelinks)

The `Psr6CacheKurzeLinks` class is a decorator that caches the results of the `create` method using a PSR-6 compatible cache pool.

#### Example

[](#example-3)

```
use tomkyle\KurzeLinks\Psr18KurzeLinks;
use tomkyle\KurzeLinks\Psr6CacheKurzeLinks;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;

$api = 'https://kurzelinks.de/api';
$key = 'your_api_key';

// Assume you have a PSR-18 compliant HTTP client, request factory, and stream factory
$httpClient = new YourPsr18Client();
$requestFactory = new YourRequestFactory();
$streamFactory = new YourStreamFactory();

$innerKurzeLinks = new Psr18KurzeLinks($api, $key, $httpClient, $requestFactory, $streamFactory);
$cachePool = new FilesystemAdapter();

$cachedKurzeLinks = new Psr6CacheKurzeLinks($innerKurzeLinks, $cachePool);

$shortUrl = $cachedKurzeLinks->create('https://example.com');
echo $shortUrl;  // Outputs the shortened URL, possibly from cache
```

### PassthroughKurzeLinks

[](#passthroughkurzelinks)

The `PassthroughKurzeLinks` class is a simple implementation of `KurzeLinksInterface` that returns the original URL without shortening it. This can be useful for testing or as a default behavior.

#### Example

[](#example-4)

```
use tomkyle\KurzeLinks\PassthroughKurzeLinks;

$passthroughKurzeLinks = new PassthroughKurzeLinks();

$shortUrl = $passthroughKurzeLinks->create('https://example.com');
echo $shortUrl;  // Outputs the original URL: https://example.com
```

### CallableKurzeLinks

[](#callablekurzelinks)

The `CallableKurzeLinks` class is a decorator that allows a `KurzeLinksInterface` implementation to be invoked directly as a callable.

#### Example

[](#example-5)

```
use tomkyle\KurzeLinks\CallableKurzeLinks;
use tomkyle\KurzeLinks\Psr18KurzeLinks;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;

$api = 'https://kurzelinks.de/api';
$key = 'your_api_key';

// Assume you have a PSR-18 compliant HTTP client, request factory, and stream factory
$httpClient = new YourPsr18Client();
$requestFactory = new YourRequestFactory();
$streamFactory = new YourStreamFactory();

$innerKurzeLinks = new Psr18KurzeLinks($api, $key, $httpClient, $requestFactory, $streamFactory);
$callableKurzeLinks = new CallableKurzeLinks($innerKurzeLinks);

// Use as callable
$shortUrl = $callableKurzeLinks('https://example.com');
echo $shortUrl;  // Outputs the shortened URL

// Use create method directly
$shortUrl = $callableKurzeLinks->create('https://example.com');
echo $shortUrl;  // Outputs the shortened URL
```

Best Practice: Usage Recommendation
-----------------------------------

[](#best-practice-usage-recommendation)

To ensure efficient usage of the [kurzelinks.de](https://kurzelinks.de) API, especially considering the restrictive rate limits, it is highly recommended to utilize the `RateLimitKurzeLinks` and `Psr6CacheKurzeLinks` decorators together. These wrappers help manage API requests effectively by limiting the rate at which requests are sent and caching responses to avoid unnecessary duplicate requests.

### Why Use Rate Limiting?

[](#why-use-rate-limiting)

The `RateLimitKurzeLinks` decorator enforces a delay between API requests. This is crucial when working with services that impose strict limits on the number of requests allowed per hour. By introducing a delay, you reduce the risk of exceeding these limits and receiving errors from the API due to overuse.

### Why Use Caching?

[](#why-use-caching)

The `Psr6CacheKurzeLinks` decorator caches the results of the `create` method. This is particularly useful when the same URL is shortened multiple times within a short period. Instead of making multiple API requests, the cached result is returned, which saves on API quota and improves performance by reducing network latency.

### Recommended Implementation

[](#recommended-implementation)

Below is a recommended setup that combines both `RateLimitKurzeLinks` and `Psr6CacheKurzeLinks`:

```
use tomkyle\KurzeLinks\Psr18KurzeLinks;
use tomkyle\KurzeLinks\RateLimitKurzeLinks;
use tomkyle\KurzeLinks\Psr6CacheKurzeLinks;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;

$api = 'https://kurzelinks.de/api';
$key = 'your_api_key';

// Assume you have a PSR-18 compliant HTTP client, request factory, and stream factory
$httpClient = new YourPsr18Client();
$requestFactory = new YourRequestFactory();
$streamFactory = new YourStreamFactory();

$kurze_links = new Psr18KurzeLinks($api, $key, $httpClient, $requestFactory, $streamFactory);

// Wrap the cached implementation with rate limiting
$rate_limited = new RateLimitKurzeLinks(kurze_links, 4000); // 4000ms sleep

// Create a PSR-6 cache pool (e.g., using Symfony's FilesystemAdapter)
// and wrap the rate-limited implementation with caching
$cachePool = new FilesystemAdapter();
$cached = new Psr6CacheKurzeLinks($rate_limited, $cachePool);

// Use the cached, rate-limited implementation
$shortUrl = $cached->create('https://example.com');
echo $shortUrl;  // Outputs the shortened URL
```

Interface
---------

[](#interface)

### KurzeLinksInterface

[](#kurzelinksinterface)

The `KurzeLinksInterface` defines the contract for creating short links.

#### Method

[](#method)

- `create(string $url): string`
    Creates a short link representation for the given URL.

#### Example

[](#example-6)

Any class implementing this interface must define the `create` method:

```
use tomkyle\KurzeLinks\KurzeLinksInterface;

class MyKurzeLinks implements KurzeLinksInterface
{
    public function create(string $url): string
    {
        // Your implementation here
    }
}
```

License
-------

[](#license)

This library is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance51

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Every ~95 days

Total

4

Last Release

341d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/412560?v=4)[Carsten Witt](/maintainers/tomkyle)[@tomkyle](https://github.com/tomkyle)

---

Top Contributors

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

---

Tags

link-shortenerlink-shortener-apishortenerurlshortenerurl shortenerlink-shortenershortening

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tomkyle-kurzelinks/health.svg)

```
[![Health](https://phpackages.com/badges/tomkyle-kurzelinks/health.svg)](https://phpackages.com/packages/tomkyle-kurzelinks)
```

###  Alternatives

[yourls/yourls

Your Own URL Shortener

11.9k27.7k1](/packages/yourls-yourls)[laracrafts/laravel-url-shortener

Powerful URL shortening tools in Laravel

97110.7k](/packages/laracrafts-laravel-url-shortener)[gallib/laravel-short-url

A Laravel package to shorten urls

16516.4k](/packages/gallib-laravel-short-url)[vinelab/url-shortener

URL shortening the easy way.

6217.2k](/packages/vinelab-url-shortener)[rezzza/shorty

Underwear for your long urls

1315.3k1](/packages/rezzza-shorty)

PHPackages © 2026

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