1

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.

Ilian Andreev
  • 1,071
  • 3
  • 12
  • 18

2 Answers2

1

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)

Andrew Willis
  • 2,289
  • 3
  • 26
  • 53
  • I agree about the ajax requests and informing the user ... that's what I was thinking as well, just don't know how many simultaneous request can be done. Preprocessing is not an option. – Ilian Andreev May 22 '12 at 11:35
  • Even if you don't do it via AJAX (using Synchronous requests in JavaScript) you'd get the desirable effect of informing the user but then only one request gets sent at a time. – Andrew Willis May 22 '12 at 11:39
  • I'll accept your answer because of the effort and extensive replies that you gave, matched my understanding actually – Ilian Andreev May 22 '12 at 17:49
1

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.

  • I though about that as well, but thanks for the comment anyway :) – Ilian Andreev May 22 '12 at 11:37
  • It would be good but the problem would be, depending on the size of each order and the number of orders sent, you'd need to write the script to order the post data by size and send packets, which requires more scripting on both the client and server side. If each order is the same size it'd be easier though. – Andrew Willis May 22 '12 at 11:40