Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!