[英]php for “high-traffic” websites
I have read that PHPs "probable" weakness is how it handles "concurrency". 我已经读过PHP的“可能”弱点是它处理“并发”的方式。 With only sessions and cookies to keep track of user state, how can PHP handle the following situations with high accuracy:
只有会话和cookie来跟踪用户状态,PHP如何高精度地处理以下情况:
multiple users check out with one item that has only 1 stock in inventory (sorry for grammar mistakes, but you pretty much get the picture already) 多个用户签出一个只有1个库存库存的项目(抱歉语法错误,但你已经得到了很多照片)
multiple users logging into the same user account using the same login details 多个用户使用相同的登录详细信息登录同一用户帐户
multiple users editing an the same image at the same time (though this rarely happens in real life) 多个用户同时编辑同一图像(虽然这在现实生活中很少发生)
or any other transactions that demands multiple thread handling 或任何其他需要多线程处理的事务
(I apologize if I misused terms here) (如果我在这里误用了条款,我道歉)
These aren't necessarily problems for PHP. 这些不一定是PHP的问题。 These are problems for developers to overcome given any technology of choice.
这些是开发人员在选择任何技术时都要克服的问题。
These aren't real concurrency issues. 这些不是真正的并发问题。 While it's true that PHP as an environment lacks in thread capability, any web server utilizing a PHP module will have multiple threads, each with thier own active PHP environment inside it, all utilizing the same resources.
虽然PHP作为一个环境缺乏线程功能,但任何使用PHP模块的Web服务器都将拥有多个线程,每个线程都有自己的活动PHP环境,所有线程都使用相同的资源。 You would run into these problems with Java, .Net, Perl, or any other web application language.
您可能会遇到Java,.Net,Perl或任何其他Web应用程序语言的这些问题。
As far as I'm aware, no language uses threads to accomplish any of these tasks. 据我所知,没有语言使用线程来完成任何这些任务。 Because of the stateless nature of HTTP communication, cookies are sessions are a mainstay of every web language, so no matter what platform you use, you're going to see very much the same strategy in all of them for handling a given problem.
由于HTTP通信的无状态特性,cookie是会话是每种 Web语言的支柱,因此无论您使用什么平台,您都会在处理给定问题的所有平台中看到非常相同的策略。
Just like all languages you'll need to find some way of locking these files. 就像所有语言一样,您需要找到一些锁定这些文件的方法。 If you're new to concurrency you might start out here and do some research on the different methods available to you.
如果您不熟悉并发性,可以从这里开始,并对可用的不同方法进行一些研究。
But the real question I have is whether this is actually going to be a problem. 但我真正的问题是这实际上是否会成为一个问题。 And if you are going to be in a high concurrency system how high is the damage in the case of a collision.
如果你要进入一个高并发系统,那么碰撞时的损坏程度会有多高。 If the cost of a collision is really high, it might be work contracting out to someone who already has cut their teeth on this and just watch what methods they use.
如果碰撞的成本非常高,那么可能会将工作外包给那些已经开始研究并且只关注他们使用的方法的人。
Have you ever heard of database transactions? 你听说过数据库交易吗? Used properly, these can fix all of your problems (which aren't PHP problems, by the way).
如果使用得当,这些可以解决所有问题(顺便说一下,这不是PHP问题)。
If your question is about transactions, then the answer is yes, but it is not a feature of the language itself. 如果你的问题是关于交易的,那么答案是肯定的,但它不是语言本身的一个特征。 Transaction safety is the task of the database layer (usually a relational database like MySQL).
事务安全是数据库层的任务(通常是像MySQL这样的关系数据库)。
But if I read your question like "Is PHP scalable?", then the answer also is yes. 但是,如果我读到你的问题,如“PHP可扩展吗?”,那么答案也是肯定的。
PHP handles "concurrency" just as perfect as possible, because it hides any concurrency related details completely from the application, which is a good thing for web applications. PHP处理“并发”尽可能完美,因为它完全隐藏了与应用程序相关的任何并发相关细节,这对Web应用程序来说是一件好事。 It makes applications inherently scalable, just as HTTP made the "web" scalable.
它使应用程序具有固有的可扩展性,就像HTTP使“Web”可扩展一样。 HTTP is stateless, so PHP is stateless in a sense.
HTTP是无状态的,因此PHP在某种意义上是无状态的。 This allows easily horizontal scalability, eg by adding more hardware without change to the application code (though this still requires some application support beforehand).
这允许容易的水平可伸缩性,例如通过添加更多硬件而无需更改应用程序代码(尽管这仍然需要事先提供一些应用程序支持)。
Check out these great articles for an explanation. 查看这些精彩的 文章以获得解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.