Tuesday, October 6, 2020

How does php and apache handle multiple requests?

 Requests are handled in parallel by the web server (which runs the PHP script).

Updating data in the database is pretty fast, so any update will appear instantaneous, even if you need to update multiple tables.

Regarding the mish mash, for the DB, handling 10 requests within 1 second is the same as 10 requests within 10 seconds, it won't confuse them and just execute them one after the other.

If you need to update 2 tables and absolutely need these 2 updates to run subsequently without being interrupted by another update query, then you can use transactions.

EDIT:

If you don't want 2 users editing the same form at the same time, you have several options to prevent them. Here are a few ideas:

  1. You can "lock" that record for edition whenever a user opens the page to edit it, and not let other users open it for edition. You might run into a few problems if a user doesn't "unlock" the record after they are done.
  2. You can notify in real time (with AJAX) a user that the entry they are editing was modified, just like on stack overflow when a new answer or comment was posted as you are typing.
  3. When a user submits an edit, you can check if the record was edited between when they started editing and when they tried to submit it, and show them the new version beside their version, so that they manually "merge" the 2 updates.

There probably are more solutions but these should get you started.

No comments:

Post a Comment