Slow down file restricted file

1

I have a file in php proceso.php that receives information in looping via jquery and makes a request to another page with curl, this file does something around 4 to 5 thousand requests one by one, everything worked much more after I restricted access to the file using sessions through the code:

ob_start();
session_start();

if(isset($_SESSION["numlogin"])){
    $n1 = $_GET["id"];
    $n2 = $_SESSION["numlogin"];
    if($n1 != $n2) { }

}else{
    header("location:index.html");
}

The return of the data was very slow before it returned on screen 2 up to 3 json arrays per second plus now every 8 seconds returns an array only, I believe that it is because it performs session checking on every request how can I improve it? / p>

my process.php

<?php
error_reporting(0);

ob_start();
session_start();

if(isset($_SESSION["numlogin"])){
    $n1 = $_GET["id"];
    $n2 = $_SESSION["numlogin"];
    if($n1 != $n2) { }

}else{
    header("location:../../../index.html");
}


$dados = $_POST["entrada"];
$nome = explode("|", $dados)[0];
$data = explode("|", $dados)[1];

function GetStr($string, $start, $end){
$str = explode($start, $string);
$str = explode($end, $str[1]);
return $str[0];
}


$ch = curl_init();
$url = "";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "nome=$nome&data=$data");
$resultado = curl_exec($ch);
curl_close($ch);

$valor = GetStr($resultado, '<a href="/logout.html" title="sair" class="btn btnSair">',"</a>"); 

if ($valor == "Sair") {
$dds = array("consulta 1" => $nome, "data" => $data, "resultado" => "existe");
} else {
$dds = array("consulta 4" => $nome, "data" => $data, "resultado" => "nao existe");
}

echo json_encode($dds);

ob_end_flush(); 

?>
    
asked by anonymous 04.11.2017 / 05:36

1 answer

2

This is possibly occurring because session_start locks the read at the same time. Two processes can not read the same file, so the same user can not load two pages at a time while the cURL of the first one is not finalized.

Change:

session_start();

To:

session_start();
session_write_close();

This should be enough so that other processes can read the same file. Using write_close just says it will not write anything, but you can still read the session normally.

    
05.11.2017 / 18:00