Home > Net >  Page reload after form submit is taking a long time
Page reload after form submit is taking a long time

Time:10-22

I have a user input page on my website where to log in they go through various forms on the same page. Each time a form gets submitted the page gets reloaded. This all of the forms thus far. However, the last one that got added has a bug. When "submit" is clicked the page loads for 45 - 75 seconds and only redirects at the end.

I investigated the error logs and access logs and I can see that the form data is posted immediately but takes the time to receive a response. I don't know what is slowing it down though, because the page does not run instantaneously (I added error messages on the page).

No data is being dealt with in that time, i.e. the page is not trying to deal with the form data, it doesn't have the form data yet.

If I go back and retry the same form submit (or try resending the post to the page), it goes really quickly so it could be a cached library or that the 302 redirect has found the correct page the second time around.

There are points in the code where I change the Location header to move to a different page (this happens right after the final form is dealt with) so that could be the source of the 302, but I also do this with other versions of the form and there are no long wait times.

My .htaccess also does switch http to https which could cause the 302, but I don't explicitly call http and the header shows scheme:https

http header

post timings

These are the error messages I made. First one is the last line before the form is submitted, second one is the first line of the page when it reloads. error_log timings

I don't think there is any code I wrote running while the post is waiting, if you think there is though, I'm happy to add more error logs.

CodePudding user response:

@Justinas was right, it was an un-optimized db query. The error logs were not outputting for some reason until my db query returned. That made all the error logs look like they were output within milliseconds of each other according to the timestamps. I fixed the query and the page now loads quickly.

  • Related