Request Timing in `$.ajax` is sometimes above 1 se

2019-05-23 14:09发布

问题:

I am using xampp version 1.7.7 on windows 7. I am trying to do that when you click save image it would send information to save_record.php in the background. I do this with

$.ajax({
      url: 'save_record.php',
      data: values.join("&"),
      success: function(data) {
            //document.write(data);
          }
    });

And it is clearly not the issue. The problem is that the response is very slow and I am unable to find the reason for it. Below I add the data I received from chrome speed tracer. Firebug is also showing all responses above 1 second. They come in format like 1055ms or 1035ms which makes me think it gets stuck somewhere for one second. If that was not weird enough, it starts making the requests fast (30-50ms) at some time and that is a perfectly usable application for me. Otherwise that 1 second delay is killing it. I once killed process explorer.exe and added as a new task and it worked. But the next time it didn't. I restarted the pc - it is one second... And while I was typing this question it started doing those fast requests. Once it starts doing them fast it's all good, but when I start xampp (or open my laptop from sleep) it is usually slow (1sec+). This is a somewhat self solving problem after some time (like 5-10mins usually), but it is annoying and both curious as why this is happening :) Hopefully I was clear about the problem.

P.S. I tested and the difference in time from first php tag to last one is ~20 ms, so I assume it is not PHP cache that is acting up?

P.S.2. I would provide any other data needed, just not sure what to look at :) Just name it.

UPDATE: added Chrome's network tab.

UPDATE: after reinstallation of xampp the problem still persists:

回答1:

Uncommenting the line 127.0.0.1 localhost in C:\Windows\System32\drivers\etc\hosts solved the problem. The speed just jumped up incredibly. I found this advice in here. Actually even the speed of Chrome opening other pages increased a lot o.O



回答2:

Can you take a screen shot of network > Timing tab of chrome developer tool for the request which takes more than a second and share it. For eg.

You must analyze the time taken for each action mentioned in that tab. And also check the event trace from the speed tracer to get more information.



回答3:

Try changing the content of save_record.php to <?php die(); ?> and see what happens. I suspect it's some kind of delay in processing the save_record operation on the server-side (could be DB is the bottleneck, could be file I/O, etc).



回答4:

save_record.php , what code have you written if you doing any database operation may the operation is taking to much time can you provide me the code of "save_record.php" the i can able to optimize response or can able solve your query