简体   繁体   English

表单提交后页面重新加载需要很长时间

[英]Page reload after form submit is taking a long time

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.单击“提交”时,页面会加载 45 - 75 秒,并且仅在最后重定向。

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, ie 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.如果我返回并重试相同的表单提交(或尝试将帖子重新发送到页面),它会运行得非常快,因此它可能是一个缓存库,或者 302 重定向第二次找到了正确的页面。

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.代码中有一些点我将 Location 标题更改为移动到不同的页面(这发生在处理最终表单之后),因此这可能是 302 的来源,但我也对其他版本的并且没有很长的等待时间。

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我的 .htaccess 也确实将 http 切换到 https,这可能会导致 302,但我没有明确调用 http 并且标头显示scheme:https

http标头

发布时间

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 计时

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.我不认为我写的任何代码在帖子等待时运行,如果你认为有,我很乐意添加更多错误日志。

@Justinas was right, it was an un-optimized db query. @Justinas 是对的,这是一个未优化的数据库查询。 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.我修复了查询,现在页面加载速度很快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM