Question

I'm going to give you an abstract of the system. It has orders and every order needs to be processed by an external API. Normally around 100 200 orders need to be processed at a time so it would be a time consuming task. Currently I use normal post request with the order ids passed in and I've increased PHP resources to some extent.

The main concern: Don't know if for some reason the script uses up all the resources and stops. This is very undesired because it may stop at any time during execution, the other thing is I don't want to allocate too much resources as I know this is also a bad idea.

So I was wondering if I use multiple AJAX requests for every order, wouldn't that be better actually? It would certainly take more time overall because of making the request and instantiating the objects and stuff every time. But I will be quite sure that the allocated resources won't be used up and the script will complete successfully. It also gives me the possibility to inform the user interactively about how many orders have been processed.

Any feedback from experienced users is welcome.

Was it helpful?

Solution

If you run multiple AJAX requests, they will run in parallel so'd take less time but more resources.

In my opinion you should use AJAX because, as you say, you can inform the user of the processes and it's better to do this then have the user not knowing what is happening.

If you were on a page and it froze for 30 seconds while processing, you'd not know if the script had crashed or whatever, but if it was for 60 seconds but informing you of the progress, you'd be more inclined to wait for it to finish.

You could also pre-process orders when they are added, then finish processing when the orders were completed (depending on your order process mechanism)

OTHER TIPS

An ajax call, able to handle >1 orders could be even better, without knowing anyway the details of your system. Continuous ajax calls are also a (server) resource.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top