views:

49

answers:

3

I sometimes wonder what happens when you submit a form multiple times and the internet server is processing the previous request? Is there any problems that can be caused in any special condition?

Edit Any problems at the client end? for example when webserver send two responses?

A: 

On e-commerce sites, people have accidentally purchased multiple times because they were impatient and kept hitting the submit button before waiting for (the sometimes slow) response.

It's a good idea to disable the submit button after it had been pressed in this type of application.

Diodeus
Disabling the submit button is not a terribly reliable solution, but it is one more thing you can do.
deceze
+2  A: 

Each form submit will be processed separately, possibly many in parallel. Depending on your application this may or may not screw up data server-side. The server-side script may stop processing if the HTTP connection is dropped though (upon clicking "Submit" again, the first request is canceled and a new request send).

To avoid problems with multiple submissions, you can for example send a unique ID with the form that will be checked on the server and can only be used once. Or you can set an "already-processing" flag in the user's session. Or you can work with job-queues and check if a job for the user already exists. The specifics would depend on your application.

Re: "Any problems at the client end? for example when webserver send two responses?"

Whenever your browser sends a request, it establishes a connection to the server on which it will wait for a response. New request, new connection. When you click a submit button a second time, the first connection is dropped and a new one established (that's also the point where the server usually stops processing the old request). That's why you can load multiple pages of the same site in a browser at the same time, it won't get confused which response is meant to go into which tab.

deceze
A: 

One simple solution that doesn't require careful synchronization or coordination between threads is to reconcile actions that occurred too close together after the fact. Did a user click on two ads half a second apart? Unlikely they actually visited the first site. Did a user submit two orders for the same bag of goods a minute apart? Probably a mistake.

As long as you have a way to identify identical events or even "from the same person" too close together, you can use this technique.

Kevin Peterson