dykyi-roman / online-visitors-counter
Online visitors counter
Requires
- php: >=5.6
- predis/predis: ^1.1
Requires (Dev)
- phpunit/phpunit: ~6.0
This package is not auto-updated.
Last update: 2024-11-16 15:29:44 UTC
README
- First we need a MySQL table to store our information
CREATE TABLE online_visitors( session_id CHAR(100) NOT NULL DEFAULT '', time INT(11) NOT NULL DEFAULT '0' );
or use Redis.
-
We are checking if the session has been already started, if it's not, then start the session
-
We created two variables, one is the current time and the other contains the current time minus n minutes
-
We need to check the session_id is already stored or not, so we query the database and see if it doesn't exist, then we'll store it and if it does exist, we will update the session's time in the DB
-
We get the count of the total session
-
We then check if the session has been in the database for more than 10 minutes, if it is, then we will delete it.
Installation
Composer
The preferred way to install this extension is through Composer.
Either run
composer require dykyi-roman/online-visitors-counter "dev-master"
or add
"dykyi-roman/online-visitors-counter": "master"
to the require section of your composer.json
Driver Support
- Redis
- Mysql
Plans for the future
- Support MSSQL Driver
- Support Memcached Driver
Usage
use Dykyi\Driver\MySQLDB; use Dykyi\DBFactory; use Dykyi\VisitorsCounter; $dbFactory = new DBFactory(); $dbFactory->setDriver(MySQLDB::class); $dataBase = $dbFactory->makeDB(['127.0.0.1','homestead','homestead','secret']); $repository = $dbFactory->getRepository($dataBase); echo VisitorsCounter::getCount($repository);
Author
Dykyi Roman, e-mail: mr.dukuy@gmail.com