Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
How to run ajax call simultaneously - php

It may be a silly question but I can't easily figured it out why it behave like this

I have two ajax call function,

execCommand() : for execute shell command through php

shell_exec('ping 127.0.0.1 > ../var/log/tmp.log');

getLog() : for collecting logs of execCommand() [../var/log/tmp.log] and display to user [live read]

echo file_get_contents(../var/log/tmp.log);

This is the jquery ajax script

    $("#docker_install_fek").on("click",function(){

        $('#progress-window').show();
        getLog();
        execCommand();
    });

    function execCommand(){

        $.ajax({
            url: '<?php echo $block->getUrl('meta/reports/ajax',[]);?>',
            type: 'POST',
            data:{ip:$("#ip").val()},
            success: function(data) {
                alert(data);
            },
            error: function() {
                alert("fail");
            }
        });

    }
    function getLog() {

        $.ajax({
            type: "GET",
            url: "<?php echo $block->getUrl('meta/reports/progress',[]);?>",
            dataType: "text",
            success: function (data) {
                $("#progress-window").empty();
                $("#progress-window").append("<pre>"+data+"</pre>");
                $("#progress-window").scrollTop(1E10);
                setTimeout(getLog, 3000);
            },
            headers: {
                "Range" : "bytes=-500"
            }
        });
    }

I notice in firebug net tab, both ajax calls are loading but it never render the log untill execCommand() finish the execution.

I don't know what is the main reason, I test like run ping 127.0.0.1 > ../var/log/tmp.log from terminal then comment execCommand() now getLog() function update log file every 3 seconds.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You are using sessions. On the server-side, sessions are locked so you can only have the session files open by one script at a time.

If you have server-side scripts that should be non-blocking, then either don't use session_start() in them, or be sure to close the session with session_write_close() as soon as you can, to allow other scripts to run.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda