在看書的時候,看到安裝PHP兩種模式,分別是PHP Module和PHP CGI。常常搞不清楚有什麼不一樣,唯一的差別在於執行Script方式,前者是和Web Server綁在一起,執行起來特別地快,而且一些設定都依附在Web Server上,但~需要注意到安全性考量,不然~會把Web Server也拖跨;反觀後者,是PHP與Web Server是切開的,在穩定性和安全性都比較高,需要跑PHP Script時才會執行,所以~每執行一支PHP Script都會耗一些CPU和Process,兩者皆有優缺點,重點是依需求選擇安裝模式,下面引用文章有簡短說明。
- Question:
What are the differences between running PHP as an Apache module and running it as a CGI binary on a Linux server?
- Answer:
One of the biggest differences between a PHP Apache module and a PHP CGI binary is that the Apache module is just that: a module of Apache that is dependent on the web server. They are intrinsically linked. If one goes down, so does the other. A PHP CGI binary is separate program entirely that runs under a different user than the web server. If something goes wrong with PHP, Apache is generally unaffected.
The primary benefit of PHP as a module is speed. When the web server loads, all of the PHP settings and configurations are loaded with it. They stay resident in the memory as long as Apache is resident and running. The drawback is the decreased security of having PHP code run by the Apache user and the fact that any changes to configuration files require an Apache restart. The advantage of PHP as CGI is the stability and security of an independent user running PHP. One of the drawbacks is that it has execute PHP for each instance of a script, which can take a heavier toll on the CPU and create a larger number of processes.
Both methods have benefits and drawbacks, and it is up to the server administrator to decide which is the best for a given situation. Once a policy is set, it is not a good idea to change it, because such a major reconfiguration could adversely affect running scripts and applications. Decide what the best course is for you and stick to it.
沒有留言:
張貼留言