Answer the question
In order to leave comments, you need to log in
What if multiple users access the script at the same time?
There is the following bundle:
apache - php - mysql
or
nginx - php - mysql
Actually questions: What happens when
1) different users access at the same time different php scripts on the nginx or apache server?
2) and if at the same time and to one script ? 3) several users simultaneously requested data from the database (MySQL)
using a script , for example, to render a dynamic page (and if this same page is not cached on the server)?
4) you need to simultaneously write to one table (MySQL) data from several
users? For example, did they post a comment at the same time?
It is interesting in the context of apache/nginx - php - mysql.
How is the processing of simultaneous requests from different users in the logic of the described servers, in the logic of php and mysql? Are requests queued, executed in parallel, or are there some errors?
And in which direction to dig to figure it out? Thanks in advance.
Answer the question
In order to leave comments, you need to log in
1) different users access different php scripts on nginx or apache server at the same time?
The question is not very clear. How do different users access different php scripts?
Users access the web server (apache/nginx), and scripts (from the point of view of the script) are accessed by only one user, on behalf of which apache/nginx itself is running.
How multitasking works in apache/nginx you can read the specifications. But parallel processing of the same script is not a problem.
2) and if at the same time and to one script?
The same
3) several users simultaneously requested data from the database (MySQL) using a script, for example, to render a dynamic page (and if this same page is not cached on the server)?
Again, the request comes from a single user running a web server that runs the php script that makes the request. A normal database is written to handle many parallel queries. Therefore, it makes sense to raise such a question only for very loaded servers, when there is not enough speed, and you need to go into optimization / clustering.
4) do you need to simultaneously write data from several users to one table (MySQL)? For example, did they post a comment at the same time?
Mysql will process requests one by one, in the order in which they are received. Precisely because it is not different scripts that are written to the database at the same time, but the database server itself - it will queue parallel requests and execute them.
The whole question revolves around a banal and common mistake for beginners.
I considered something from base, processed and I want to write down.
What happens if the base changes between these events?
Correct answer: the base should not change between these events.
Either locking records, or - and preferably - proper queries that make getting data and changing it atomic.
Some of the above are lined up in a queue, some of which can work in parallel (this is configurable).
Well, there can be errors, of course, if the code is not designed for parallel operation.
1) and 2) different users will run the script, nothing else will happen. There can be problems if this script writes data to a file. In this case, the data in the file will be from the last one who launched the script, and in case of writing to the end of the file, we will get a mess :)
3) and 4) working with the database over the network, there is a connector queue and locks, and these are server problems not a script, don't worry. You need to worry if the database is in a file, for example sqlite, msaccess, that's where the locks need to be handled by yourself.
So after all, the script is the same index.php, that is, the site itself, in fact) If it’s completely on your fingers, then the server is the folder where the files are stored, and the browser views these files (this is HTTP), what happens if a million a person will request an index.php file? The server will give it to them, because it's just viewing it. It's not multitasking, it's just accessing a file. Another question is if this script writes something to another text file (not to the database, the database is just multitasking), then locks will occur there and anything in general, up to its damage. But this is a question from another area, and you are asking about HTTP.
I apologize for the amateurish question, but the desire to know requires asking.
For example, I have 2 scripts on the server. Both work like this:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question