I want to implement an algorithm that requires a lot of independent calculations using JavaScript for drawing the results (using Canvas) and PHP to do the calculations on the server. So my idea is to create a PHP script for handling a fracture of those calculations and call it multiple times using AJAX. Each call calculating a portion of the algorithm's current iteration step.
Does this result in multithreading on the server in the way that i.e. I make 100 AJAX calls to the script they will be handled simultaneously on the server as soon as they arrive?
Do you have any ideas how I can synchronize this in JavaScript? I need to make sure each AJAX call finishes before entering the next iteration step. Is there something like a best practice for that?
Thanks a lot!
Generally in a case where we are sure to receive continuos data from server, we maintain the http connection state so that the server can directly push data to the client without the need for client to poll continuously.
This can be achieved using web sockets. Ratchet is a good library for php.
In a case where you absolutely have to use the polling approach, you can have the success function of each AJAX call to make the next AJAX call.