Pankaj
Pankaj

Reputation: 10105

Database is not responding until all requests are submitted successfully: MySQL

I am using Laravel 5.3 for Web API and below is my JQuery Ajax request which saves records concurrently. Below is the code..

for (i = 0; i < 100; i++) {
    var 
     data={'Role' : "Role"+i},
     request = $.ajax({
        url:                'http://localhost:1234/Practise/public/api/SaveRoleApi',
        type:               "POST",
        data:               JSON.stringify(data),
        contentType:        "application/json; charset=utf-8",
        async:  true,
        success: function(d){ console.log(d); }
     });
}

I am using for loop to save 100 records. Please check there is async: true,. Reason I said it is saving records concurrently because the requests are being submitted randomly although I confirmed that all requests are being submitted successfully.

My Question is: I can't submit select statement select * from tblrole until all the above ajax requests are submitted.

Problem is: Database is not responding until all requests has been submitted.

What should I do to retrieve records during the Post request(s) submission is in progress?

Below are my Phpmyadmin details.

enter image description here

Upvotes: 4

Views: 416

Answers (3)

snitch182
snitch182

Reputation: 723

Are you using the same browser and the same webserver for your app and phpmyadmin ? Usually a server waits for one request to finish before it lets you do another. Try using a different browser for phpmyadmin.

Upvotes: 1

Rick James
Rick James

Reputation: 142306

Perhaps this is the confusion...

async has to do with getting a response, not on submitting in parallel.

The code you presented is single-threaded -- submit one request, submit another request, ..., but don't wait for them to finish.

Then, only after 100 submits, perform the SELECT.

I would guess that AJAX chokes on that many submissions and gets stalled.

Upvotes: 2

Rick James
Rick James

Reputation: 142306

Smells like you have autocommit=0 and never issued a COMMIT. Please show us the connect code, plus some of the SQL statements. I assume it is in SaveRoleApi.

Smells like "table locking", which you get from MyISAM. If your tables are that, change to InnoDB.

Upvotes: 1

Related Questions