Reputation: 8885
Before I have started to do web-programming I had thought it was easy. Now, after a year of experience I think it can be really damn hard mainly because of concurrency issues.
Because that was some very unexpected finding out, I tried to ask my more experienced friends (they had made some apps like e-shops etc.) about it. Specifically, I asked them if you can really have concurrency issues that you need to solve or otherwise you are at danger of your data becoming inconsistent and they were like: "hmm, never thought of that". That made me a bit afraid of my sanity and not even some exhausting web search have persuasively answered the question.
Hence, here I am to make sure that rails of my mind do not lead to a very white polstered room:
1) supposing LAMP framework, is it possible for two php scripts run by apache to overlap in execution in any possible manner?
2) is it possible for the same script to be run more than once at the same time with its instances overlapping in any possible manner?
3) was the LAMP choice important or does the same thing holds for like any web-development environment used today?
4) If the concurrency really can be a problem and i am not just making things up, is there any theory that would help me to wrap my head around it and solve these problems like this: "hey look, there is a possible concurrency issue" and after a while: "hey, this is a classic example of X, which can be solved this way".
5) why programmers tend to look at web development as not being "kosher" while thinking they could do it easily? (no need to answer this but that fact pisses me off now while I know it used to be the same with me)
I know, this is probably multi-sucky-general question from the stackoverflow's point of view but I have nobody really experienced around me that could help.
Upvotes: 1
Views: 772
Reputation: 92657
I don't really think the principles of protecting shared resources is too much different between web apps and standard desktop programs. Resources are resources and an app can be run more than once unless you specifically prevent multiple instances.
1) supposing LAMP framework, is it possible for two php scripts run by apache to overlap in execution in any possible manner?
Yes. Apache can run requests in threads/processes. Two PHP script requests could run at the same time.
2) is it possible for the same script to be run more than once at the same time with its instances overlapping in any possible manner?
Yes. Apache can run requests in threads/processes. Two PHP script requests could run at the same time.
3) was the LAMP choice important or does the same thing holds for like any web-development environment used today?
Apache has the methodology of running requests in multiple threads. There are other servers that use an async approach. Either way, you shouldn't rely on the web server to provide guards against concurrent ops in your code. That is the responsibility of your code to check resources.
4) If the concurrency really can be a problem and i am not just making things up, is there any theory that would help me to wrap my head around it and solve these problems like this: "hey look, there is a possible concurrency issue" and after a while: "hey, this is a classic example of X, which can be solved this way".
It really comes down to the resources of your code, and what you are sharing. If a script for instance needs to work with the filesystem, then your code should be checking via some type of synchronization. Databases tend to handle that for you with internal locking to rows or tables.
5) why programmers tend to look at web development as not being "kosher" while thinking they could do it easily? (no need to answer this but that fact pisses me off now while I know it used to be the same with me)
I am sure people that don't know how to do web design (especially server side) think its all just typing up word documents. Once you do it, you realize its a lot of work.
Upvotes: 3