pixelbart/helpful

using wp_remote_get slamming server with hundreds of requests per minute

Closed this issue · 5 comments

Hello,

After updating from 4.4.x to 4.5.6, I noticed our server get slammed by requests from itself for the same file over and over:

[23/Mar/2022:09:57:41 -0400] "GET /wp-content/plugins/helpful/templates/emails/feedback-email.txt HTTP/2" 200 296 "https://www.hockinternational.com/wp-content/plugins/helpful/templates/emails/feedback-email.txt" "WordPress/5.9.2; https://www.hockinternational.com"

In the course of 10 minutes while I was figuring out what happened, there were over 1,400 such requests (we have a fairly active site). We are not even using the email feature. The server requesting the same static file via HTTP from itself 200,000 times a day is just plain bad logic and programming - incredibly inefficient and demanding on the server especially compared to the old way of simply requiring the file directly and using ob_get_contents().

I see the changelog filled with some comments about changing how this file is read, but the current way seems to be the worst of all of the choices and a terrible workaround to whatever issues it might be trying to fix with certain hosts that must be configured very poorly if they can't require a file and get its contents with an output buffer.

I'm glad to brainstorm and test other ideas with you, but wp_remote_get is not the correct solution to whatever the original problem was. What exactly was the issue with the old way?

Thanks,

Kevin

Hello @KevinPlusPlus

I will undo it because I find ob_start much better too. I am trying to solve problems. If others don't report problems, I assume it's good. Now that you have reported a problem and I can also understand this error, I will do it again with ob_start and point out in the future that you have to look for a better hoster.

ob_start has the problem on 1&1 server that the memory limit is reached. It may be a messy solution for you, but is just a problem for most. 1&1 and IONOS are unfortunately very strong. But I will undo it, simply because I like your problem description better, since it is now a problem that Helpful causes and not a server.

If you don't like my programming work, you can always contribute, or program a better plugin. Just as information by the way.

Greetings Kevin

Hello,

Sorry for my tone in my previous messages and for your help. I understand your frustration; I have also been working with some other developers who had workarounds for specific hosts and my frustration is more aimed at the gymnastics that are required for poor or cheap hosting packages, which isn't your fault. People want to pay $5 a month and expect blazing fast and flawless performance!

What was the issue with file_get_contents? I didn't try any of those versions that used file_get_contents, but that seems programmatically like it would be even better. Was it also a memory issue? I am glad to investigate and test alternatives.

Kevin

@KevinPlusPlus

Here the problem was that if you worked on the localhost (local PC or similar) with Helpful, that file_get_contents set the url wrong. Since I have heard more often about people working on the local machine (instead of a virtual server under proper conditions), I had to find another solution for this.

I guess wp_remote_get worked very well there. But now it's back to ob_start and wp_cache so that the variable is only retrieved once on a load and not multiple times.

The variables are retrieved because Helpful always pulls the default variables (here the keys are used to check if an option is in the context of Helpful or not).

I think this way it is ok now. Should not cause any more problems for you either.

I had just run the update.


Right, that bothers me also always very strongly. In Germany, this is a big problem that people see no value in it. But that's the way it is, unfortunately.

Stay healthy and thank you for your answer!

Greetings Kevin

Hi,

Is there a way to detect certain conditions and then choose conditionally which method is used? For example, if running locally (not 100% sure how you'd check for that), use wp_remote_get? Or see if ob_start returns false, then try another method? (Hard to imagine output buffering starting successfully but then running out of memory buffering a small text file?)

Just riffing ideas here based on stuff I've seen in other plugins to work around goofy issues like this.

Kevin

Hi,

Is there a way to detect certain conditions and then choose conditionally which method is used? For example, if running locally (not 100% sure how you'd check for that), use wp_remote_get? Or see if ob_start returns false, then try another method? (Hard to imagine output buffering starting successfully but then running out of memory buffering a small text file?)

Just riffing ideas here based on stuff I've seen in other plugins to work around goofy issues like this.

Kevin

I'll definitely have to take a look again. ob_start only causes problems on IONOS. But maybe that is already history, with the wp_cache_set solution that I had now implemented.

Let's see and wait until someone gets back to me. Thanks for your thoughts!!!

Greetings Kevin