PHPackages                             jonathanmaron/increment-version - 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. jonathanmaron/increment-version

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

jonathanmaron/increment-version
===============================

increment-version helps you programmatically maintain a .version file in the root directory of your project that contains a version number. Using this version number it is trivial to programmatically invalidate URIs to resources with a long expires header (stored, for example, in a CDN) in your build scripts.

2.0.1(8y ago)0408[1 PRs](https://github.com/jonathanmaron/increment-version/pulls)BSD-3-ClausePHPPHP ^7.1

Since Feb 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jonathanmaron/increment-version)[ Packagist](https://packagist.org/packages/jonathanmaron/increment-version)[ Docs](https://github.com/jonathanmaron/increment-version)[ RSS](/packages/jonathanmaron-increment-version/feed)WikiDiscussions master Synced 3w ago

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

Increment Version
=================

[](#increment-version)

When working with a CDN, in which CSS, JS and image files have expire headers a long way into the future, it is very convenient to be able to invalidate a cache programmatically when an existing file is overwritten.

For example, when the `styles.min.css` file is re-built, if something changes in the source SASS file.

One way to invalidate the CDN is to change the URI of the resource, for example, by placing a version number in the URI:

```
http://www.example.com/application-x.x.x/css/styles.min.css

```

where `x.x.x` is the version number.

`increment-version` offers an easy-to-use CLI API to maintain a `.version` file in the the root of your project.

Using the `.version` file, your application can then construct the URI containing the version number.

Please note that `increment-version` supports only numeric semantic version numbers, and not semantic version numbers, containing build and pre-release components.

For example, `increment-version` supports `1.2.3`, but does not support `1.2.3-alpha.1+build.12345.ea4f51`.

Example Usage
-------------

[](#example-usage)

### Initialize Your Project

[](#initialize-your-project)

```
increment-version --path="/var/www/www.example.com" --init

```

### Set the `.version` File to 0.0.5

[](#set-the-version-file-to-005)

```
increment-version --path="/var/www/www.example.com" --set="0.0.5"

```

### Increment the Major Number of the `.version` File

[](#increment-the-major-number-of-the-version-file)

```
increment-version --path="/var/www/www.example.com" --major

```

### Increment the Minor Number of the `.version` File

[](#increment-the-minor-number-of-the-version-file)

```
increment-version --path="/var/www/www.example.com" --minor

```

### Increment the Patch Number of the `.version` File

[](#increment-the-patch-number-of-the-version-file)

```
increment-version --path="/var/www/www.example.com" --patch

```

### Increment the Major, Minor and Patch Numbers of the `.version` File

[](#increment-the-major-minor-and-patch-numbers-of-the-version-file)

```
increment-version --path="/var/www/www.example.com" --major --minor --patch

```

How to Use in Your Project
--------------------------

[](#how-to-use-in-your-project)

- In the build script that compiles SASS to CSS
- In the build script that compiles CoffeeScript to Javascript
- In the build script that optimizes image files

In each of the above cases, it makes sense to increment the `.version` file to force the web browser to download a new version of the resource that has just been created.

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

[](#installation)

Installation is via composer:

```
cd ~/install-path

composer create-project jonathanmaron/increment-version

```

It is recommended to include `~/bin` in your `PATH` variable:

```
PATH=$PATH:~/install-path/increment-version/bin

```

so that `increment-version` is available to the logged in user globally.

Aliasing the URI
----------------

[](#aliasing-the-uri)

Ín the root public directory of your web project, you should create a directory in which you will store all the resources with a long expires header.

For example, `application-0.0.0`.

Using Apache's mod\_alias, you can then create the following rule:

```
AliasMatch "^/application-(\d{1,10}).(\d{1,10}).(\d{1,10})/(.*)$" "/var/www/www.example.com/public/application-0.0.0/$4"

```

which essentially removes the version number from the URI. For example:

```
/application-1.2.3/img/logo.jpg

```

is mapped to:

```
/application-0.0.0/img/logo.jpg

```

This is the actual storage location of the file on the file system.

Major, minor and patch numbers of up to 10 digits are supported in the above example.

Adding the Version to the URI
-----------------------------

[](#adding-the-version-to-the-uri)

The easiest way to add the version number to the URI of a resources is to write a helper function and wrap all embedded URIs with this function.

The helper function reads the `.version` in the root directory and adds it to the URI.

And alternative method is two write a function which has access to the entire HTML of the page (Zend Framework Finish Events, for example). The function should simply search for `application-0.0.0` replacing it with the version number stored in .version.

And thus the circle is closed.

You simply have to remember to update the .version whenever anything is overwritten and you can then be 100% certain that the web browser will always retrieve the most current version of the resource references in the pages' HTML.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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 ~165 days

Recently: every ~206 days

Total

6

Last Release

2946d ago

Major Versions

1.0.3 → 2.0.02018-05-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/18d8bc9bdee8ab1b0cfccce6a06d2438acbed3a58b0046c4834c5678f6769342?d=identicon)[jonathanmaron](/maintainers/jonathanmaron)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/jonathanmaron-increment-version/health.svg)

```
[![Health](https://phpackages.com/badges/jonathanmaron-increment-version/health.svg)](https://phpackages.com/packages/jonathanmaron-increment-version)
```

###  Alternatives

[shlinkio/shlink

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

5.0k4.9k](/packages/shlinkio-shlink)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

101466.4k45](/packages/friendsoftypo3-content-blocks)

PHPackages © 2026

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