I have a php api that is being accessed via Flash. It grabs some content for flash and then does some book keeping. The problem is, the book keeping can take several seconds, 开发者_如何学Pythonand the php api can be accessed in the same manner anywhere from 10-500 times before the Flash App has loaded everything from it.
Sense I'm using flash to access it, AJAX isn't an option. I want to be able to tell the flash URL Loader that the page is done loading before the book keeping, but I still need to do the book keeping. How can this be achieved? Or can it?
This sounds like a situation where you want to use background processing to do the heavy work. Even if you could finish sending your request to the browser, if you continued to do more processing, you would tie up the php thread which would not be able to service another request. If you have several requests coming in, you will quickly have a bottleneck at the "book keeping" step.
Have a queue that you shove your data into, and have a background process consume items from the queue, processing each item in turn. This way you can quickly service requests to the server, and defer processing for later processing.
For a queue system, you can use things like rabbitmq, or some other simpler queueing mechanism(perhaps a DB table). There are probably a thousand ways to handle this offline processing.
The main thing is to defer processing of anything that will take a while and can wait to be processed later.
精彩评论