dykyi-roman/online-visitors-counter

dev-master 2017-10-01 10:22 UTC

This package is not auto-updated.

Last update: 2024-11-16 15:29:44 UTC


README

  1. 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.

  1. We are checking if the session has been already started, if it's not, then start the session

  2. We created two variables, one is the current time and the other contains the current time minus n minutes

  3. 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

  4. We get the count of the total session

  5. 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