jan199674
jan199674

Reputation: 753

Using the same script for all users

Imagine a website with several users logged in from different IP's all trying to do the same thing at the time using the same PHP-code - for example uploading an image to a folder or some text to database with AJAX.

How will the script react to that?

Upvotes: 1

Views: 46

Answers (3)

Mureinik
Mureinik

Reputation: 311978

There is no apriori issue with several users executing the same PHP code at once. The code itself, however, should be aware that it may be executed concurrently and handle such scenarios, especially when accessing a shared resource such as a folder on the disk or a database. For example, it must not assume the id of the row it insert to the database or the name of the file it creates, but must generate them in a safe away (e.g., using a auto_increment column, or naming the file by using a UUID).

Upvotes: 1

ALPHA
ALPHA

Reputation: 1155

It doesn't matter how many users ( it matters of course but as for this question lets say little amount of uses) connect to your apache server.. when a user connects to the server and the php script executes each and every user will be allocated a thread from the server's thread pool. so every user's tasks will be handled parallel. Until you reach the threads limit of the server

if that happens you will need to balance the load by adding new servers and distribute the load from servers

Upvotes: 0

SirPilan
SirPilan

Reputation: 4857

The php-script isnt exclusive to a request. Every request is handled if there is a new request while the script for another request is still running it gets handled in a new thread (up to a certian limit depending on webserver and configuration). As soon as the handle-limit is reached the request is on hold, unitl enough resources are free to handle the new request.

Upvotes: 1

Related Questions