I’m using WooCommerce’s ‘REST API’ (worst decision ever) in an attempt to bulk insert/edit products from an external feed. This is working great on my end, but there simply must be something WooCommerce is failing on itself and it’s getting in the way of my own progress, because a certain (variable) way through any of my attempts to do bulk insert/edit in quantities of 100 a time, I will get an error reporting Invalid JSON returned for...
.
wooStockUpdate: Saving products to WooCommerce via bulk update/insert
wooStockUpdate: 4% products processed - estimated time left: 2394.48s
wooStockUpdate: 9% products processed - estimated time left: 2758.21s
wooStockUpdate: 14% products processed - estimated time left: 2412.816s
wooStockUpdate: 19% products processed - estimated time left: 2308.176s
wooStockUpdate: 23% products processed - estimated time left: 2961.035s
wooStockUpdate: 28% products processed - estimated time left: 2047.248s
wooStockUpdate: 33% products processed - estimated time left: 2017.906s
wooStockUpdate: 38% products processed - estimated time left: 1881.7s
wooStockUpdate: 42% products processed - estimated time left: 2359.295s
Invalid JSON returned for http://wholefoodearthdev/wc-api/v3/products/bulk?...
201
Each time it reports a percentage (and estimated time, because anything using a REST API takes hours) it has completed an iteration of sending the individual bulks of 100 items to WooCommerce. During one of these the error occurs, and it isn’t dependent on what’s being sent.
Even though it errors out, it still returns a 201 - Created
HTTP status, because it has created at least some of the 100 products, and I’ve looked at the code, it just reuses the singular creation code, so it fails in returning the right status code for the bulk failing, since one of the items succeeded.
Most importantly, every time this occurs, it happens to have also been running for pretty much exactly 180 seconds, so I believe this is a time-out on WooCommerce’s side as I’ve been setting my CURL request and PHP time-outs at 6 hours. So what I need to know is the most painless way to force WooCommerce to, you know, finish. I’m not really supposed to be editing WooCommerce either, so if it’s possible without doing that (and preferably without server reconfiguration), it’ll be great.
I imagine if this is really just complete oversight by WooCommerce, there will be no choice but editing it, but hopefully they’ve just missed something on the documentation explaining how to set the timeout limit. I’ve not seen anything like that so far, but have noticed other things it would have been a lot of help to have known earlier, that were also missed out of the documentation, so who knows…
You should increase
default_socket_timeout
inphp.ini
, also if you are using standard woocommerce library you have to increaseconst TIMEOUT
invendor/automattic/woocommerce/src/WooCommerce/HttpClient/Options.php