Performance of my website

0

Good community,

In this way I use the sessions in the main file to differentiate the interfaces of a common user to an administrator, for example:

<?php
  session_start();
  if (isset($_SESSION['usuario']))
  {
    if ($_SESSION['usuario']['desc_tipo_usuario'] != "adminEmpresa")
    {
      header('Location: adminEmpresa.php');
    }
  }
  else {
    header('Location: index.php');
  }
?>

But currently I have more than 15 PHP files within which I declare the use of SESSIONS:

session_start();
  $nit_empresa = $_SESSION['usuario']['nit'];
  $id_empresa  = $_SESSION['usuario']['id_empresa'];

I have checked each one of the querys and all of them respond with a prudent speed for the loading of data (eg use of variable):

SELECT
pemp.nombre_punto,
cdes.ciudad,
cdes.id_departamento,
dpto.departamento,
pemp.descripcion_punto,
tusr.id_tipoDeUsuario,
tusr.desc_tipo_usuario,
empr.id_empresa,
empr.nit,
empr.ruta_logo,
prna.usuario,
prna.password

FROM puntoempresa pemp
INNER JOIN ciudades cdes
ON cdes.id_ciudad = pemp.id_ciudades_punto    
INNER JOIN departamento dpto
ON dpto.id_departamento = cdes.id_departamento        
INNER JOIN persona prna
ON prna.id_usuario_punto = pemp.id_puntoEmpresa
INNER JOIN tipodeusuario tusr
ON tusr.id_tipoDeUsuario = prna.id_tipoUsuario
INNER JOIN empresa empr
ON empr.id_empresa = prna.empresa_per
WHERE empr.nit = '$nit_empresa'
AND empr.id_empresa = '$id_empresa'

Later on in my consultations I use them as variables to have a much more structured query of the data, but my doubt arises as to what the use of the sessions in all my CRUD files, is altering the loading speed of all the project as such.

Since at the moment of using "F5" or using the update button the browser takes an average load of 15 seconds, which bothers most users who use the system.

Looking for a bit I found this type of problem, how could you optimize the use of sessions?:

  

Heavy user sessions: Each user accessing the site or web application requires a memory capacity for the server to process their requests and deliver the content. If this need for resources is very high, the slowness of the service will become noticeable exponentially each time more users access. In this case you should review and optimize the code to make each session lighter or increase the resources available correctly

    
asked by jecorrales 19.09.2017 в 18:34
source

2 answers

1

Something similar happened to me with the performance and I found that in fact I was calling the database many times for data that did not change often, let's say the users persmios eg. then I began to store more session variables with more static data and the system ended up working wonderfully, another thing is that I started using indexes in the queries to the database, I went from reading 5000 claims records and at least 4 observations each claim in 15s to read 13000 records at that time.

    
answered by 21.09.2017 в 04:44
0

Use ajax to not reload your page and only update the information on your page that the user needs. You can see tutorials on how to use it, such as JQUERY's easy code. and so you avoid reloading the session or use cookies

    
answered by 19.09.2017 в 18:55