与 admin-ajax.php 相关的加载时间问题(带有 PINGDOM 结果链接)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22705185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:12:01  来源:igfitidea点击:

Load time Issues related to admin-ajax.php (with PINGDOM results link)

phpajaxwordpresspingdom

提问by user2189801

I am trying to get the load times on my website down. It loads really slowly and iv tried a couple of solutions.

我正在尝试减少我网站上的加载时间。它的加载非常缓慢,iv 尝试了几种解决方案。

  1. Using gmetrix to solve issues such as optimizing images .
  2. Using pingdom to see what the issues are.
  1. 使用gmetrix解决优化图片等问题。
  2. 使用 pingdom 来查看问题所在。

As listed in the below link are the pingdom stats. http://tools.pingdom.com/fpt/#!/cKIvOz/http://healthyeatingandliving.ca/

以下链接中列出的是 pingdom 统计信息。 http://tools.pingdom.com/fpt/#!/cKIvOz/http://healthyeatingandliving.ca/

I have no clue what admin-ajax.php is and why the load on that is so high. Also if anyone knows what the first line is in the file/path column .

我不知道 admin-ajax.php 是什么以及为什么它的负载如此之高。此外,如果有人知道文件/路径列中的第一行是什么。

If there is anything else i can do to make the load times less since right now its a pain trying to edit content. Thank you to everyone who looks at this.

如果我还能做任何其他事情来减少加载时间,因为现在尝试编辑内容很痛苦。感谢所有看到这个的人。

回答by Konstantinos

You should add this code to functions.php inside your theme.

您应该将此代码添加到主题中的functions.php。

add_action( 'init', 'my_deregister_heartbeat', 1 );
function my_deregister_heartbeat() {
    global $pagenow;

    if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow )
        wp_deregister_script('heartbeat');
}

This code will disable the admin-ajax.php feature and reduce CPU by 75%.

此代码将禁用 admin-ajax.php 功能并将 CPU 减少 75%。

回答by Sourish

Screenshot of Network-tab in inspectorUse the heartbeat control plugin and disable it. Also, in gtmetrix, click on the waterfall chart and then click on post as indicated in the image to figure out whats wrong.

检查器中网络选项卡的屏幕截图使用心跳控制插件并禁用它。此外,在 gtmetrix 中,单击瀑布图,然后单击图像中所示的帖子以找出问题所在。

It's a call to the ajax features from a wp plugin called wptouch.

这是从名为wptouch的 wp 插件调用 ajax 功能。

回答by Steve Nisbet

I've spent a witless few days trying to sort this same issue out, I've even used the deregister_heartbeat code - to no effect. I wanted to share a solution I put in place to keep Apache / MySQL from dying whilst you try to find out what's going on.

我花了几天的时间试图解决同样的问题,我什至使用了 deregister_heartbeat 代码 - 没有效果。我想分享一个我实施的解决方案,以防止 Apache / MySQL 在您试图找出发生了什么时死亡。

In the endafter creating a test copy of the site on a different server and swapping to a default theme I was able to work out that an extention engine in a child theme was making Ajax calls that were somehow getting past the deregistered heart beat - we've now ditched the engine and will probably write the child-theme from scratch.

最后,在不同的服务器上创建站点的测试副本并切换到默认主题后,我能够确定子主题中的扩展引擎正在进行 Ajax 调用,但不知何故超过了取消注册的心跳 - 我们现在已经放弃了引擎,可能会从头开始编写子主题。

To buy me some time whilst tracking the offending stuff down I needed a way to drop the threads from the webserver before they occupied all available spaces - and we have a big webserver - it was nonetheless causing sites to crash after only an hour since an Apache restart. You can of course employ a hard Apache restart (apachectl restartor service apache restarton a Debian machine) - but this kills all connections - and in a multi-host environment its going to mess someone up. If you are on an *NIX system, you can do the following, it requires w3m(or equivalent braile-modebrowser that can run dumps from the CLI like elinks, lynx or links)

为了在跟踪有问题的东西的同时给我一些时间,我需要一种方法在线程占用所有可用空间之前从网络服务器中删除它们 - 我们有一个大型网络服务器 - 尽管如此,它仍然导致网站在一个小时后崩溃,因为 Apache重新开始。您当然可以使用 Apache 硬重启(Debian 机器上的apachectl restartservice apache restart) - 但这会杀死所有连接 - 在多主机环境中,它会使某人陷入困境。如果您在 *NIX 系统上,您可以执行以下操作,它需要w3m(或等效的盲文模式浏览器,可以从 CLI 运行转储,如 elinks、lynx 或链接)

#!/bin/bash
kill `w3m -dump http://<server address>/server-status | grep "admin-ajax.php"|awk '{print }'`

Make sure you get the backticks right after the kill and at the end of the script. We basically use w3m to hit the server-status page (you need to have this enabled in your Apache config - make it available only from a local IP address, it gives a lot away) - we pipe the results through grep just hone in on processes that deal with admin-ajax.php- and then we feed those lines into awkwhich basically returns a list of the associated PIDnumbers to the killcommand.

确保在杀死之后和脚本结束时立即获得反引号。我们基本上使用 w3m 来访问服务器状态页面(您需要在您的 Apache 配置中启用此功能 - 使其仅可从本地 IP 地址使用,它会提供很多信息) - 我们通过 grep 传递结果,只是磨练处理admin-ajax.php 的进程- 然后我们将这些行输入awk,它基本上将相关PID编号的列表返回给kill命令。

The result is that the process threads in Apache will die - but will appear for a short while in any server-status list as open slot with no current process- subsequent hits to your site will occupy these threads in a normal fashion again

结果是 Apache 中的进程线程将死亡 - 但会在任何服务器状态列表中出现一小段时间作为没有当前进程的开放插槽- 您站点的后续点击将再次以正常方式占用这些线程

We put the whole thing into a crontask running every 5 minutes or so - effect is we got the threads appearing, but they never stayed around long enough to cause issue.

我们将整个事情放入每 5 分钟左右运行一次的cron任务中 - 结果是我们让线程出现,但它们从未停留足够长的时间导致问题。

回答by Robert Lee

The issue with the ajax load time is with woocommerce scripts running even when you do not have any of the functions needed for your shop on certain pages. I would consider what theses individuals did and have the scripts removed from your regular pages (sorry the website is a little old so you may want to double check and update the enqueue script variables). But to get the gist of it you would basically be removing plugins that are not necessary for the pages that do not require woocommerce functions.

ajax 加载时间的问题在于,即使您在某些页面上没有商店所需的任何功能,woocommerce 脚本也会运行。我会考虑这些人做了什么,并将脚本从您的常规页面中删除(抱歉,该网站有点旧,因此您可能需要仔细检查并更新排队脚本变量)。但是要了解它的要点,您基本上会删除不需要 woocommerce 功能的页面不需要的插件。

http://wordimpress.com/how-to-load-woocommerce-scripts-and-styles-only-in-shop/

http://wordimpress.com/how-to-load-woocommerce-scripts-and-styles-only-in-shop/

or

或者

http://gregrickaby.com/remove-woocommerce-styles-and-scripts/

http://gregrickaby.com/remove-woocommerce-styles-and-scripts/

You could also add some conditional tags so that it specifically does not load on certain pages.

您还可以添加一些条件标签,以便它不会在某些页面上加载。

https://codex.wordpress.org/Conditional_Tags

https://codex.wordpress.org/Conditional_Tags

回答by Michael

Another plugin or the theme is using something like a cart widget that refreshes when you add to cart etc, this uses admin-ajax and will load on every page, if you deactivate WooCommerce then the problem goes away but the issue is something that depends on WooCommerce.

另一个插件或主题正在使用类似购物车小部件之类的东西,它会在您添加到购物车等时刷新,这使用 admin-ajax 并将在每个页面上加载,如果您停用 WooCommerce,那么问题就会消失,但问题取决于WooCommerce。