CGI,fastCGI,php-cgi,php-fpm都是什么?
CGI(Common Gateway Interface)全称是“通用网关接口”,WEB 服务器与PHP应用进行“交谈”的一种工具,其程序须运行在网络服务器上.
但是CGI有个蛋疼的地方,就是每一次web请求都会有启动和退出过程,也就是最为人诟病的fork-and-execute模式,这样一在大规模并发下,就死翘翘了。
因此出现了fastCGI
FastCGI是语言无关的、可伸缩架构的CGI开放扩展,其主要行为是将CGI解释器进程保持在内存中,并因此获得较高的性能。众所周知,CGI解释器的反复加载是CGI性能低下的主要原因,如果CGI解释器保持在内存中,并接受FastCGI进程管理器调度,则可以提供良好的性能、伸缩性、Fail- Over特性等等。
处理流程 :
- 当客户端请求到达Web Server时,FastCGI进程管理器选择并连接到一个CGI解释器。Web server将CGI环境变量和标准输入发送到FastCGI子进程php-cgi。
- FastCGI子进程完成处理后,将标准输出和错误信息从同一连接返回Web Server。当FastCGI子进程关闭连接时,请求便告处理完成。FastCGI子进程接着等待,并处理来自FastCGI进程管理器(运行在Web Server中)的下一个连接。 php-cgi是php官方编写的FastCGI管理程序.虽然是php官方出品,但是这丫的却一点也不给力,性能太差,而且也很麻烦不人性化,主要体现在:
- php-cgi变更php.ini配置后,需重启php-cgi才能让新的php-ini生效,不可以平滑重启。
- 直接杀死php-cgi进程,php就不能运行了。 PHP-FPM负责管理一个FastCGI进程池,来处理来自Web服务器的请求.并实现了平滑重启
遍历文件件下所有文件
<?php
function getFilesByDirectory(string $dir, array $path = []) : int
{
if (!is_dir($dir)) {
$pathStr = implode('/', $path);
echo $pathStr.'/'.$dir."\n";
return 1;
}
$pathStr = implode('/', $path);
echo $pathStr.'/'.$dir."/\n";
$handle = opendir($dir);
$subDir = readdir($handle);
//echo "dir----". $dir."\n";
while ($subDir !== false) {
if ($subDir == '.' || $subDir == '..') {
$subDir = readdir($handle);
continue;
}
//echo 'sub dir is : '.$subDir."\n";
$path[] = $dir;
getFilesByDirectory($subDir, $path);
array_pop($path);
$subDir = readdir($handle);
}
closedir($handle);
return 1;
}
getFilesByDirectory($argv[1] ?? '')
?>
## 添加测试文件
# mkdir dirRoot
# cd dirRoot
# mkdir a
# mkdir a/aSSSS
# touch a1
# touch file1
# 调用 php /tmp/readdir.php /tmp/dirRoot
输出 :
//tmp/dirRoot/
/tmp/dirRoot/a/
/tmp/dirRoot/a/aSSSS
/tmp/dirRoot/file1
/tmp/dirRoot/a1
array_merge 与 + 区别
array_merge:合并两个数组 , +:按index合并当index相同时保存前一个数组的值 当键名相同时
-
键名类型为字符串时,array_merge后面的值会把前面的值覆盖掉
-
键名类型为数字时,array_merge不会覆盖
-
+号,不管键名类型为字符串或数字,当键名相同时,前面的值逗号把后面的值覆盖掉
# nginx和fastcgi的两种通信方式
# TCP
# socket:
参考
www.awaimai.com/371.html
php-fpm.org/about/
www.zybuluo.com/phper/note/…