R
R
riazantsev962016-04-23 17:49:41
PHP
riazantsev96, 2016-04-23 17:49:41

How to handle parallel requests to the online store?

To learn PHP and SQL, I am making a simple online store from scratch.
The database has already been designed and the script for its creation has been written.
There were questions about handling both HTTP requests and database requests.
Created two users in the database, a store visitor and an administrator. The PHP script connects to the MySQL server. Depending on who has entered the site, one or another user is connected.
Question 1. What happens if two visitors connect to the database? Could this be? Can PHP scripts run in parallel? Is it possible to connect to the database in parallel using the same database user?
Question 2: If concurrent connections can occur to the database, how can I synchronize access? For example, readers (visitors) view products, and a writer (administrator) updates prices or adds a new product. Need to apply transactions or locks? Or transactions with a certain lock level?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2016-04-23
@riazantsev96

What happens if two visitors connect to the database?

If the DBMS implies multi-user data processing (MySQL is one of them), then everything will be in order. Moreover, modern client-server DBMSs are needed so that many client applications can connect to them and send requests. Hundreds and thousands of connections is a normal situation for a busy site.
Of course, otherwise how to get acceptable responsiveness for the site?
In general, it depends on the DBMS, sometimes it is possible to limit the number of TCP connections for one DB user. But as a rule, by default, this restriction is not set, and usually all running instances of the script use one user to connect. Sometimes different database users are used for different scripts in order to increase security - for example, for ordinary visitors - a user with a smaller set of rights, and for an administrator or manager - another user with full access to the database. Then, in the case of an exploitable SQL injection, the consequences will not be so significant. [In such an architecture, usually each database user corresponds to one role in the application (administrator / content manager / regular visitor)].
I don't know what you mean by "lock level", but you should definitely become familiar with transaction isolation levels .
If you understand the levels of isolation, you will get answers to such questions. In particular, read commited (the default isolation level in most relational DBMSs) just solves the problem of concurrent reads and updates.
In general, you should definitely get acquainted with transactions, especially since you have taken an online store as a training task. Only in this case can this educational project be considered completed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question