PHP作为一种流行的服务器端脚本语言,其执行方式多样,以下将通过实例表格形式展示几种常见的PHP执行方式。

fastcgiExternalServer /usr/local/bin/php-cgi -socket /tmp/php-fastcgi.sock -pass-header Authorization
|

| FastCGI方式 | PHP作为FastCGI进程池的一部分执行,性能优于CGI |

fastcgi_pass 127.0.0.1:9000;
|

| SAPI (Server API)方式 | PHP作为Web服务器的一部分执行,如Apache模块、Nginx模块等 |

location ~ "".php$ {

    include fastcgi_params;

    fastcgi_pass 127.0.0.1:9000;

    fastcgi_index index.php;

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    include fastcgi_params;

}
 |

执行方式描述实例代码
命令行执行通过命令行工具执行PHP脚本
phpindex.php
CGI方式PHP作为CGI程序执行,每个请求独立启动一个PHP进程
Location/index.php