PHPackages                             mmdm/sim-hit-counter - 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. mmdm/sim-hit-counter

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

mmdm/sim-hit-counter
====================

A simple yet nice hit counter library

v0.1.0(5y ago)013MIT

Since Nov 2Pushed 5y ago1 watchersCompare

[ Source](https://github.com/mmdm95/sim-hit-counter)[ Packagist](https://packagist.org/packages/mmdm/sim-hit-counter)[ RSS](/packages/mmdm-sim-hit-counter/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Simplicity Hit-Counter
======================

[](#simplicity-hit-counter)

A simple library for count users' hits.

Attention
---------

[](#attention)

PLEASE NOTE THAT this library is good only for small websites so... DO NOT USE THIS for high traffic websites and use more professional tools to handle huge database and server overheads.

Install
-------

[](#install)

**composer**

```
composer require mmdm/sim-hit-counter
```

Or you can simply download zip file from github and extract it, then put file to your project library and use it like other libraries.

Just add line below to autoload files:

```
require_once 'path_to_library/autoloader.php';
```

and you are good to go.

Architecture
------------

[](#architecture)

This library use database to have its best performance

**Collation:**

It should be `utf8mb4_unicode_ci` because it is a very nice collation. For more information about differences between `utf8` and `utf8mb4`in `general` and `unicode` please see [this link](https://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci) from `stackoverflow`

**Table:**

- hits

    This table contains all hits.

    Least columns of this table should be:

    - id (INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO\_INCREMENT)
    - url (TEXT NOT NULL)
    - type (VARCHAR(20) NOT NULL)
    - view\_count (BIGINT(20) UNSIGNED NOT NULL DEFAULT 0)
    - unique\_view\_count (BIGINT(20) UNSIGNED NOT NULL DEFAULT 0)
    - from\_time (INT(11) UNSIGNED NOT NULL)
    - to\_time (INT(11) UNSIGNED NOT NULL)

How to use
----------

[](#how-to-use)

First of all you need a `PDO` connection like below:

```
$host = '127.0.0.1';
$db = 'database name';
$user = 'username';
$pass = 'password';
// this is very nice collation to use
$charset = 'utf8mb4';

$dsn = "mysql:host={$host};dbname={$db};charset={$charset}";
$options = [
    // add this option to show exception on any bad condition
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
];
try {
    $pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
    throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
```

Then create hit counter instance and use its methods

```
$hitCounter = new HitCounter($pdo);

// use hit methods
$hitCounter->hitDaily('the_url');
// ...
```

HitCounter class
----------------

[](#hitcounter-class)

#### `__construct(PDO $pdo_instance, ?array $config = null, bool $test_mode = false)`

[](#__constructpdo-pdo_instance-array-config--null-bool-test_mode--false)

`$config`: The config of yours like the one in [Architecture](#architecture).

see config file under `src/_Config` path.

`$test_mode`: By default users ip addresses that are unknown or invalid, crawlers and `DNT` header are not allowed to hit website. To prevent this check, send `true` as parameter's value.

#### `runConfig()`

[](#runconfig)

To make config working and create tables, call this method.

#### `hitDaily(string $url)`

[](#hitdailystring-url)

Make a daily hit.

#### `hitWeekly(string $url)`

[](#hitweeklystring-url)

Make a weekly hit.

#### `hitMonthly(string $url)`

[](#hitmonthlystring-url)

Make a monthly hit.

#### `hitYearly(string $url)`

[](#hityearlystring-url)

Make a yearly hit.

#### `hit(string $url, int $hit_at_times = IHitCounter::TIME_ALL)`

[](#hitstring-url-int-hit_at_times--ihitcountertime_all)

Make a hit for a specific period of time according to second parameter. please see [Constants](#constants) section

**Note:** You can use multiple constants together with `|` operator

#### `report(?string $url, int $from_time, int $to_time, int $hit_with_types = self::TYPE_ALL): array`

[](#reportstring-url-int-from_time-int-to_time-int-hit_with_types--selftype_all-array)

You can get count of *views* and *unique\_views* from specific/all url(s) from a specific time and for a specific type.

#### `freeReport(?string $url, string $where, array $bind_values = []): array`

[](#freereportstring-url-string-where-array-bind_values---array)

You can get count of *views* and *unique\_views* from specific/all url(s) with specific condition.

**Note:** You should use names parameters and put value of that parameter in `$bind_values` parameter.

#### `saveDailyHits(string $path_to_store, bool $delete_from_database = false): bool`

[](#savedailyhitsstring-path_to_store-bool-delete_from_database--false-bool)

Save all daily hits information before today in a file.

#### `saveWeeklyHits(string $path_to_store, bool $delete_from_database = false): bool`

[](#saveweeklyhitsstring-path_to_store-bool-delete_from_database--false-bool)

Save all weekly hits information before this week in a file.

#### `saveMonthlyHits(string $path_to_store, bool $delete_from_database = false): bool`

[](#savemonthlyhitsstring-path_to_store-bool-delete_from_database--false-bool)

Save all monthly hits information before this month in a file.

#### `saveYearlyHits(string $path_to_store, bool $delete_from_database = false): bool`

[](#saveyearlyhitsstring-path_to_store-bool-delete_from_database--false-bool)

Save all yearly hits information before this year in a file.

#### `saveHits(string $path_to_store, int $hit_at_times = self::TIME_ALL, bool $delete_from_database = false): bool`

[](#savehitsstring-path_to_store-int-hit_at_times--selftime_all-bool-delete_from_database--false-bool)

Save all hits information before current time in a file.

**Note:** You can use multiple constants together with `|` operator

Constants
---------

[](#constants)

There are some constants in `IHitCounter` interface class as below:

**Time constants**:

- TIME\_DAILY
- TIME\_WEEKLY
- TIME\_MONTHLY
- TIME\_YEARLY
- TIME\_ALL

**Hit types constants**:

- TYPE\_DAILY
- TYPE\_WEEKLY
- TYPE\_MONTHLY
- TYPE\_YEARLY
- TYPE\_ALL

License
=======

[](#license)

Under MIT license

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

2021d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d955ebaae3fe602e6ad26c16422f6ab25a61a436fd7f08425a5be5c73ef9025c?d=identicon)[mmdm95](/maintainers/mmdm95)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/mmdm-sim-hit-counter/health.svg)

```
[![Health](https://phpackages.com/badges/mmdm-sim-hit-counter/health.svg)](https://phpackages.com/packages/mmdm-sim-hit-counter)
```

###  Alternatives

[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[open-southeners/laravel-companion-apps

Extend your Laravel applications with companions apps (Android, iOS, PWA...)

233.9k](/packages/open-southeners-laravel-companion-apps)[cleaniquecoders/shrinkr

Shrinkr is a Laravel package for shortening URLs, with custom slugs, analytics, branded domains, and seamless API integration.

142.9k](/packages/cleaniquecoders-shrinkr)

PHPackages © 2026

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