Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to see server side http requests that take place within ajax calls? #745

Open
scottfennell-toptal opened this issue Mar 9, 2023 · 8 comments

Comments

@scottfennell-toptal
Copy link

Hello, I have the following setup...

  • Some JS makes a fetch request to my WP API endpoint.
  • The endpoint itself makes an http request to stripe.

To complicate matters, the http request to stripe is via their official php sdk, which obviously does not use wp_remote_*() and I'm treating as a black box I don't want to tamper with.

In any event, I don't see the server side http calls in query monitor. Should I expect to? Is there a way to? Some of my stripe calls seem to be taking a long time and I'd like to do some performance debugging.

@crstauf
Copy link
Contributor

crstauf commented Mar 9, 2023

Definitely should not expect to see those requests in QM.

You could use QM's profiling feature around the request, but that will only show time and memory.

@scottfennell-toptal
Copy link
Author

scottfennell-toptal commented Mar 10, 2023

Thank you for the response!

Can you elaborate on what it is about those requests that makes them impossible for QM to see?

  • Is it because they take place within the context of an ajax call to a server side proxy?
  • Is it because they do not use wp_remote_*()?
  • Is it because they use the stripe sdk?
  • Some combo?
  • Something else?

I am interested in profiling them for sure. Could you point me to any docs for that?

@crstauf
Copy link
Contributor

crstauf commented Mar 10, 2023

It is because the requests are made without using WP helper functions (ex: wp_remote_get()).

If you review the collector for the HTTP data, you'll see it connects to several WordPress hooks to watch for and gather data on HTTP requests.

You may learn some things by reading the docs on querymonitor.com. Here's the specific blog post on profiling:
https://querymonitor.com/blog/2018/07/profiling-and-logging/

@scottfennell-toptal
Copy link
Author

Now I'm tempted to tamper with the stripe sdk and make it use wp_remote_() just so I can use QM 🤣

@crstauf
Copy link
Contributor

crstauf commented Mar 10, 2023

You certainly could, but if you updated Stripe's PHP SDK version, you'd have to do it over again. It's probably more pain than it's worth, but that's ultimately your judgement.

@scottfennell-toptal
Copy link
Author

oh for sure, I just meant on staging to do some performance debugging here.

@lkraav
Copy link

lkraav commented Mar 10, 2023

Most SDK use well-known libs themselves, such as Guzzle. Could identify the lib, and write a simple QM integration plugin for it.

Although https://github.com/stripe/stripe-php/blob/master/composer.json seems to indicate they're using curl directly.

@johnbillion
Copy link
Owner

Over the years I've spent quite a bit of time investigating whether QM could automatically detect HTTP requests made with Guzzle or directly with Curl without having access to a variable that holds the instance or the handle. It's just not possible without using PHP ticks, which are way too resource intensive to use.

I have thought about writing a QM connector for Guzzle and Curl but the majority of the time it would still rely on a) a user realising that a plugin is doing such requests, and then b) some sort of modification to the plugin to expose its Guzzle instance or Curl handle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants