4

I wrote an API that takes a WooCommerce webhook and inputs the data into our CRM. I'm using:

file_get_contents("php://input");

The whole script is in one file because it's so simple.

My question is what happens if php://input receives two or more webhooks at the same time. Would it operate like a queue or could one be potentially dropped?

Reason I ask is we have multiple WC stores and I'm not sure if I need to clone the script for each store or if they could all feed into the same script.

Thanks for the help!

blibbers
  • 65
  • 3
  • 5
    Just the same as when it receives any other set of http requests...each one is processed separately, usually in the order they arrive. If they should all be processed with the same code, then you only need one script. You don't make 20 copies of your website homepage just because you might have 20 users, do you? This is no different. – ADyson Mar 21 '21 at 13:35
  • 2
    You only need multiple scripts if the scripts must do something different because it's a different store (and if it's not possible to know from the request input data which store it should be working with, and vary the behaviour that way). And of course then the scripts would all have different URLs so you'd have to configure the senders to send to different URLs. But that has nothing to do with receiving concurrent requests. – ADyson Mar 21 '21 at 13:37
  • You are totally right. I don't know why that didn't occur to me. For some reason in my head it wasn't registering as an http request. Thanks so much man. But yeah the script can identify which store so I'll just have them all feeding into one. You rock!! – blibbers Mar 21 '21 at 18:28
  • I wish I could accept your comment as the answer. Lol – blibbers Mar 21 '21 at 18:29
  • 1
    Your wish is my command...see below :-) – ADyson Mar 21 '21 at 20:37

1 Answers1

3

Just the same as when it receives any other set of http requests...each one is processed separately, usually in the order they arrive. If they should all be processed with the same code, then you only need one script. You don't make 20 copies of your website homepage just because you might have 20 users, do you? This is no different.

You only need multiple scripts if the scripts must do something different because it's a different store (and if it's not possible to know from the request input data which store it should be working with, and vary the behaviour that way). And of course then the scripts would all have different URLs so you'd have to configure the senders to send to different URLs. But that has nothing to do with receiving concurrent requests.

ADyson
  • 57,178
  • 14
  • 51
  • 63