Json taking too long to be created on the server

0

Good evening!

Personally, I'm generating a file .json by PHP , this file goes directly to the server (hosting). My problem is that as soon as I save, it gives a delay of a few minutes (2 minutes up). The code is working, it's only with this delay. Is this normal? Its size is 120 bytes , sometimes even less.

But at the same time I generate an image, and it ends up being uploaded in seconds, as soon as I finish the process, it already appears in the database.

Note: I have already tried without the image, and it gives this delay too ...

Follow my code:

<? php
ini_set('display_errors', 1);
error_reporting(E_ALL);

$nome = $_POST['nome'];
$bloco = $_POST['bloco'];
$apto = $_POST['apto'];
$rg = $_POST['rg'];
$empresa = $_POST['empresa'];
$veiculo = $_POST['veiculo'];
$placa = $_POST['placa'];
$date = date('d/m/y');
$hour = date('H:i');

// Array com dados
$visitante = array(
    'nome' => $nome,
    'bloco' => $bloco,
    'apartamento' => $apto,
    'rg' => $rg,
    'empresa' => $empresa,
    'veiculo' => $veiculo,
    'placa' => $placa,
    'foto' => $destino,
    'data' => $date,
    'hora' => $hour
);

    $dados = $visitante;
    $dados_json = json_encode($dados, true);
    $file = fopen('dados/cadastro.json', 'w+');
    fwrite($file, $dados_json);
    fclose($file);
?>

Thank you in advance.

    
asked by anonymous 30.08.2018 / 02:12

1 answer

0

Good evening,

Have you checked the apache logs?

The creation of txt files to store data is a practice that can be considered bad, because of the number of requests, or even if you are adding lines in this file one hour it will get gigantic.

It is necessary to verify how the resources of the server are, because here in my machine I did a test, and it worked correctly.

    
30.08.2018 / 02:22