I have some PHP code that connects to shopping cart API (SOAP) endpoints. This is not to one central server, but rather to any number of user's specific endpoint URLs.
Right now I have several different classes that all create their own connection to the users API.
E.G.,
CartProduct.php -> updateProduct() (creates api connection)
CartCategory.php -> updateCategory() (creates api connection)
I was thinking of using a Singleton to share the remote connection, but after reading through questions on SO, and some blogs, apparently everyone hates Singleton.
In my case I don't think a connection pool makes sense. I'm connecting to a remote user's website, so I don't just want to open 5 connections and potentially slow down their website. I think in this case I really want to share ONE connection between this call to the application. I think in the case of a DB, a connection pool makes sense, but not for remote user APIs. Now theoretically, I guess we should think about what happens if the user tries to run updateProduct and updateCategory at the same time... will that break the system?
Is there a design pattern that makes sense here to open a connection which several different classes can share??