_GET in infinite loop PHP

0

I have a php query manager that I call from AJAX with Jquery with an asynchronous GET, this manager is in charge of calling the relevant function.

One of these functions must execute a process that depends on the number of records that have been inserted until a certain date. If the number of records is small the process ends, the echo is done, ajax obtains the result and everything works correctly, but if the process is long it ends (I have a log that keeps the answer json and this is correct) but it seems that the echo is not made, since Ajax does not get any response and immediately starts the whole process again as if a new _GET call was made to the manager with the same parameters.

header("Content-Type: application/json; charset=UTF-8", true);
switch(mb_strtoupper($_GET['funcion'])){
[...]
}

$json = json_encode($respuesta);
Log::insertaLog('Gestor Consulta > Respuesta ' . $json);
// En ambos casos siempre se está guardando el registro del json y este es correcto, pero el _GET 
echo($json); flush();

The ajax call:

$.ajax({ type: "GET", async: true, url: "/Code/Herramientas/GestorConsultas.php", dataType: "json", data: parametros, success: function (datos) { console.log(datos); }, error: function (peticion, mensaje) { console.log("Error invocacio: /Code/Herramientas/GestorConsultas.php " + parametros + " " + peticion + " " + mensaje); GNR_GestionaError(arguments.callee.name, mensaje); } })

I will appreciate any help.

Edited

If I execute the call to the function without going through the manager, it always executes correctly.

    
asked by Athal 02.04.2018 в 19:33
source

1 answer

0

If the problem arises when there are several records, you are probably reaching the memory limit or the maximum execution time. You can modify these values with a file .htaccess or with the function ini_set() of php.

htaccess:

php_value memory_limit 256M          # la letra indica la unidad de memoria: Megabyte, Gigabyte...
php_value max_execution_time 300     # tiempo en segundos

ini_set:

ini_set('memory_limit', '256M');
ini_set('max_execution_time', 300);

Peeeeerooooo, before doing this I would recommend reviewing each of the processes that you are running. Try activating to show all PHP errors:

error_reporting(E_ALL);
ini_set('display_errors', true);
    
answered by 02.04.2018 в 21:00