PHP - Concurrent user control?

6

I have a finished and working system, done entirely in ASP.

I am rewriting version 2.0 of it, and as I will review it 100%, I decided to try my luck with PHP. A problem has arisen in user control:

I need to be in control of how many concurrent users are using the system, since usage monthly fee negotiations are tied to this.

In ASP the control was done through ASP Application Object , which is a kind of global object accessible by all instances running the application (more information about it in this link ).

I've fished about this but I have not found anything concrete about the best ways to do this in PHP, does anyone have any experience with something like this?

    
asked by anonymous 19.03.2015 / 21:16

1 answer

4

Without a database I would do this:

<?php
$tempoHoras = 6;
ini_set('session.gc_maxlifetime', $tempoHoras * 3600); # Tempo em segundos
ini_set('session.save_path', '/caminho/para/suas/sessoes'); # Local do salvamento

//inicia sessao
session_start();


function getUsuariosOnline()
{ 
    $count = 0; 
    $d = dir(session_save_path()) or die("Diretorio invalido.");
    while (false !== ($entry = $d->read())) 
    {
        if($entry != '.' && $entry != '..')
        {
            $count++; //Conta a qtde de arquivos dentro do diretorio de sessao
        }
    }
    $d->close();
    return $count;  
} 

$usuarios_online = getUsuariosOnline();
echo $usuarios_online;
?>

Ref: link

    
19.03.2015 / 22:20