


Which PHP mode? Apache vs CGI vs FastCGI,apachefastcgi_PHP教程
Which PHP mode? Apache vs CGI vs FastCGI,apachefastcgi
Which PHP mode? Apache vs CGI vs FastCGI
There are multiple ways to execute PHP scripts on a web server. We’re often asked about the difference between these modes, so here it is!
We offer the three most common PHP handlers across our Linux Cloud Hosting range:
- Apache module
- CGI
- FastCGI
Each of these has its own advantages and disadvantages.
Apache Module (mod_php)
Using mod_php to execute PHP scripts on a web server is the most popular method used by our customers and until recently was the default mode we set when you create a new webspace.
When using mod_php the PHP interpreter is embedded in each Apache process that’s spawned on the server. This way every Apache worker is able to handle and execute PHP scripts itself removing the need to deal with any external processes; unlike CGI or FastCGI. This makes it very useful for sites that are ‘PHP heavy’ where lots of requests are likely to contain PHP code (such as WordPress, Drupal, Joomla, etc.) because all the requests can be handled by Apache.
As the interpreter is started along with Apache, it allows it to run very quickly as it can cache certain information and doesn’t need to repeat the same tasks each time a script is executed.
The downside to this is that the footprint for each Apache process is larger as it requires more system resources with the PHP interpreter embedded. Even when serving static content such as images, text and style sheets where no PHP code needs to be executed, the process still contains the PHP interpreter.
Pros
- PHP code executed by Apache.
- No external processes required.
- Very good performance on PHP heavy sites.
- PHP configuration settings may be customized within .htaccess directives.
Cons
- Makes each Apache process footprint larger – meaning more RAM used.
- Loads PHP interpreter for non-PHP content.
- Files created by PHP scripts are usually owned by the web server so you cannot edit them via FTP later.
CGI
Executing PHP scripts with a CGI application is the legacy way of running applications on a web server, it’s highly inefficient and rarely used. It was originally introduced in the 1990’s but was deemed to be too inefficient to use on anything other than very small sites.
A benefit of running applications on CGI is that it keeps the code execution separate from the web server, which allows for some added security benefits. For example, a buggy or insecure PHP script executed via FastCGI cannot corrupt or affect security of any other files outside of the domain it’s hosted on. It also means that the PHP interpreter is only called when required, thereby allowing static content to be served solely by the web server.
The inefficiencies of running PHP with CGI support spawn from requiring a new process to be created each time any PHP code needs to be executed. As you can imagine, on busier sites or PHP based applications it can be very resource intensive.
Very few Layershift customers use this mode, and we don’t recommend it!
Pros
- Better security than mod_php (above) as PHP code execution is isolated from web server.
Cons
- Legacy way of running applications.
- Very poor performance.
FastCGI
FastCGI was introduced as a middle ground between the PHP Apache Module and the CGI application. It allows scripts to be executed by an interpreter outside of the web server and includes the security benefits of CGI but doesn’t include any of the inefficiencies of CGI.
When executing PHP scripts with FastCGI each request is passed from the web server to FastCGI via a communication socket. This allows for much greater scalability as the web server and the PHP interpreter can be split into their own individual server environments if necessary. However a similar end result can also be achieved using nginx in front of Apache (such that nginx handles basic requests itself and only passes dynamic requests to Apache) so this point alone doesn’t determine the ideal choice for a given scenario.
In a Plesk environment, FastCGI is executed as the domain FTP user and is the default PHP handler we offer on all our Linux services running the latest versions of Plesk Panel.
The downside of running PHP with FastCGI support is that any PHP directives defined in a .htaccess will not be used. As a workaround, it is possible to set PHP directives on a per domain basis with a custom php.ini file on any Plesk Panel server.
Pros
- Improved security as PHP code execution is isolated from web server.
- Static content will not be processed by PHP interpreter.
- Allows files to be managed by your FTP user without altering permissions afterwards.
Cons
- Cannot use PHP directives in .htaccess. This is expected by many popular scripts.
- Requires PHP requests to be passed from web server.
Which Should I use?
On smaller sites, it usually comes down to personal preference when deciding which mode of PHP support you want. We often see customers that are running CMS applications (such as WordPress, Drupal, Joomla, etc.) tend to prefer FastCGI as it allows FTP and PHP scripts equal access, meaning file upload and edit functionality within the CMS works as advertised without any special file permission configuration.
This is only an overview of a very complex and in-depth issue. I have presented some of the main considerations to inform your decision, but each site is unique so please contact our support team if you need further guidance. For a guide detailing how to change the PHP handler using Plesk, see our accompanying knowledgebase article.
原文:http://blog.layershift.com/which-php-mode-apache-vs-cgi-vs-fastcgi

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

Video Face Swap
Échangez les visages dans n'importe quelle vidéo sans effort grâce à notre outil d'échange de visage AI entièrement gratuit !

Article chaud

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Sujets chauds

Alipay Php ...

JWT est une norme ouverte basée sur JSON, utilisée pour transmettre en toute sécurité des informations entre les parties, principalement pour l'authentification de l'identité et l'échange d'informations. 1. JWT se compose de trois parties: en-tête, charge utile et signature. 2. Le principe de travail de JWT comprend trois étapes: la génération de JWT, la vérification de la charge utile JWT et l'analyse. 3. Lorsque vous utilisez JWT pour l'authentification en PHP, JWT peut être généré et vérifié, et les informations sur le rôle et l'autorisation des utilisateurs peuvent être incluses dans l'utilisation avancée. 4. Les erreurs courantes incluent une défaillance de vérification de signature, l'expiration des jetons et la charge utile surdimensionnée. Les compétences de débogage incluent l'utilisation des outils de débogage et de l'exploitation forestière. 5. L'optimisation des performances et les meilleures pratiques incluent l'utilisation des algorithmes de signature appropriés, la définition des périodes de validité raisonnablement,

Le détournement de la session peut être réalisé via les étapes suivantes: 1. Obtenez l'ID de session, 2. Utilisez l'ID de session, 3. Gardez la session active. Les méthodes pour empêcher le détournement de la session en PHP incluent: 1. Utilisez la fonction Session_RegeReate_id () pour régénérer l'ID de session, 2. Stocker les données de session via la base de données, 3. Assurez-vous que toutes les données de session sont transmises via HTTPS.

L'application du principe solide dans le développement de PHP comprend: 1. Principe de responsabilité unique (SRP): Chaque classe n'est responsable d'une seule fonction. 2. Principe ouvert et ferme (OCP): les changements sont réalisés par extension plutôt que par modification. 3. Principe de substitution de Lisch (LSP): les sous-classes peuvent remplacer les classes de base sans affecter la précision du programme. 4. Principe d'isolement d'interface (ISP): utilisez des interfaces à grain fin pour éviter les dépendances et les méthodes inutilisées. 5. Principe d'inversion de dépendance (DIP): les modules élevés et de bas niveau reposent sur l'abstraction et sont mis en œuvre par injection de dépendance.

Comment déboguer le mode CLI dans phpstorm? Lors du développement avec PHPStorm, nous devons parfois déboguer PHP en mode interface de ligne de commande (CLI) ...

Comment définir automatiquement les autorisations d'UnixSocket après le redémarrage du système. Chaque fois que le système redémarre, nous devons exécuter la commande suivante pour modifier les autorisations d'UnixSocket: sudo ...

Liaison statique (statique: :) implémente la liaison statique tardive (LSB) dans PHP, permettant à des classes d'appel d'être référencées dans des contextes statiques plutôt que de définir des classes. 1) Le processus d'analyse est effectué au moment de l'exécution, 2) Recherchez la classe d'appel dans la relation de succession, 3) il peut apporter des frais généraux de performance.

Envoyant des données JSON à l'aide de la bibliothèque Curl de PHP dans le développement de PHP, il est souvent nécessaire d'interagir avec les API externes. L'une des façons courantes consiste à utiliser la bibliothèque Curl pour envoyer le post� ...
