服务器启动

service rpcbind restart
service nfs restart

服务端查看 showmount -e //查看自己共享的

showmount -a //查看链接的客户端

客户端查看 showmount -e 192.168.33.10
客户端挂载 mount -t nfs 192.168.33.10:/data/www/ /data/www/packages-emao
客户端挂载时候遇到
mount clntudp_create: RPC: Program not registered
执行下 rpc.mountd 就可以了

佛家有人生三重境界之说,即:“看山是山,看水是水;看山不是山,看水不是水;看山还是山,看水还是水。反观学习的各种东西,有那一个不是如此呢。
初入门的时候,被问到服务器是怎么解析php的,会很自信的回答,nginx把请求交给php,php把执行结果返回给nginx然后响应给浏览器。这样的回答,应该是没有
任何问题的。但是请求是怎么交给php的呢?当时忙碌在每天的业务代码中,无暇也无心来关注这些。

哪现在再遇到这样的问题呢

  • 1,php是这么和nginx接受nginx的请求的 ?
  • 2,当项目需要多个php版本共存的时候该怎么做 ?

要理解nginx怎么转发请求的,需要了解几个概念,Cgi,FastCgi,这些概念不只局限于nginx-php,linux里的进程通信大都基于此。

什么是Cgi,FastCgi,php-fpm ?

CGI

CGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序须运行在网络服务器上。

CGI可以用任何一种语言编写,只要这种语言具有标准输入、输出和环境变量。如php,perl,tcl等。

FastCGI

FastCGI像是一个常驻(long-live)型的CGI,它可以一直执行着,只要激活后,不会每次都要花费时间去fork一次(这是CGI最为人诟病的fork-and-execute 模式)。它还支持分布式的运算,即 FastCGI 程序可以在网站服务器以外的主机上执行并且接受来自其它网站服务器来的请求。

FastCGI是语言无关的、可伸缩架构的CGI开放扩展,其主要行为是将CGI解释器进程保持在内存中并因此获得较高的性能。众所周知,CGI解释器的反复加载是CGI性能低下的主要原因,如果CGI解释器保持在内存中并接受FastCGI进程管理器调度,则可以提供良好的性能、伸缩性、Fail- Over特性等等。

PHP-FPM

PHP-FPM是一个PHP FastCGI管理器,是只用于PHP的。

PHP-FPM其实是PHP源代码的一个补丁,旨在将FastCGI进程管理整合进PHP包中。

在安装时,./configure的时候带 –enable-fpm 参数即可开启PHP-FPM。


了解这些我们就知道,通信的流程就是,nginx接受到请求,是通过cgi与php进行通信。
具体实现,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
修改php-fpm.conf

listen = 127.0.0.1:9000
或者
listen = /dev/shm/php-cgi.sock

修改nginx配置文件server段的配置

location ~ [^/]\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
#或
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}

这样就引刃而解了第2个问题,可以首先安装多个php版本,通过 –prefix 指定不同的目录,php-fpm启动的时候,可以选择不同的端口,或者不同的sock。然后项目里nginx配置里
指定对应的php-fpm就实现了php多个版本共存。

入IT这一行已经进入了第五个年头,有时候会想工作的意义在哪里。

纸上得来终觉浅,得知此事需躬行。

之前看phalcon框架DI的实现方式,觉得很好用,但是由于是c扩展,看不了源码,并不知道是如何实现的,后来看laravel的服务容器,发现是实现了php的SPL接口,然后用这些接口实现的。

一个典型的「container」便是实现了arrayaccess,Demo如下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

<?php
namespace skylee;

class A
{

public function say()
{

return __METHOD__;
}

}

class B
{


public function say()
{

return __METHOD__;
}
}

// 容器
class Container implements \arrayaccess
{


private $container = array();

public function __construct(array $array = [])
{

$this->container = $array;
}

public function __get($id)
{

return $this->offsetGet($id);
}

public function offsetSet($offset, $value)
{

if (is_null($offset))
{
$this->container[] = $value;
}
else
{
$this->container[$offset] = $value;
}
}

public function offsetExists($offset)
{

return isset($this->container[$offset]);
}

public function offsetUnset($offset)
{

unset($this->container[$offset]);
}

public function offsetGet($offset)
{

$raw = $this->container[$offset];

return $this->container[$offset] = $raw();
}

public function register($Manage)
{

$Manage->register($this);
}
}

// provide
interface ServiceProvide
{

public function register(Container $container);
}

class ProvideA implements ServiceProvide
{

public function register(Container $container)
{

$container['A'] = function ()
{

return new skylee\A;
};
}
}

class ProvideB implements ServiceProvide
{

public function register(Container $container)
{

$container['B'] = function ()
{

return new skylee\B;
};
}
}

class App extends Container
{

public $service = [
skylee\ProvideA::class,
skylee\ProvideB::class
];

public function __construct()
{

parent::__construct();

$this->registerProvide();
}

public function registerProvide()
{

foreach ($this->service as $v)
{
$this->register(new $v());
}
}
}

$obj = new App();

$a = $obj["A"]->say();

$b = $obj["B"]->say();

var_dump($a);

var_dump($b);

备份目录
1
2
3
rsync -av  /var/lib/data   /data  

备份 /var/lib/data 目录。-a 包含文件权限 -v 显示输出

php闭包使用示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php

class A
{

public function handel(callable $callback)
{
call_user_func_array($callback, [1,2]);

}
}

$obj = new A();

$obj->handel(function ($a, $b)
{
echo $a . $b;

});

XML字符串转数组

1
2
$xmlObj = simplexml_load_string($xmlStr);
$xmlArr = json_decode(json_encode($xmlObj) , true);
1
2
3
4
5
// 论如何用最好的编程语言获得当天零点的UNIX时间戳
echo strtotime("today midnight");

//处理数据
$_POST=array_map('addslashes',$_POST);

A better way to do a lot of IF statements:

1
2
3
4
5
6
7
8
9
10
11
switch(TRUE){
case email_is_valid($email):
// Do something.
break;
case username_is_valid($user):
// Do stuff.
break;
case pass_too_short($pass) && pass_not_save($pass):
// Other stuff.
break;
}

转眼都月半了,想着年前的时候还买了一个日记本,每一页都写着日期,以为这样就能多纪录一些东西呢,然后大半个月下来却是寥寥无几。还买了一份字帖,想来练字,一样效果甚微,没有坚持下来。至于跑步每周能跑2到3次,这个还算好一点吧。

今年的工作目标没有达成,挺遗憾吧,然而这都是无可奈何的事,就由它去吧。

成长路上运气占了很大的部分吧,从上学到毕业找工作,一切都很顺利,没经历过什么坎坷,或者换句话说,该来的总会来的,等到了那个时间也就得到了该有的东西。会娶妻生子,会活很长的一段时间。

刚到大一的时候,觉得3年是很长的时间了,工作后才发现3年也就转眼间。

在公司已经是个老人了,身边都是90后,甚至95后。

早上出门的时候飘起了雪,想来是这个冬天最后一场雪吧。

几周前在多看买的一本书,《让孩子心悦诚服》,到现在还是没有看完,最近竟然玩起了游戏,而且停不下来啊,感觉又回到了中学的时候,无知的痴迷起来,耗费了很多闲暇的时间。要多花点时间读书了。

Quick Start

Create a new post

1
2
3
4
hexo n post "title"#写文章
hexo g #生成
hexo s #预览
hexo d #部署 #可与hexo g合并为 hexo d -g

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

已写成了一个可以直接部署到线上的脚本

只适合自己用,嘿嘿,代码在家目录下,每次写完只需要快速唤起终端,执行脚步。可谓方便快捷。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh

read -p "Please input your book name:" book

cd /Users/skylee/Gitbook/Library/import/$book

gitbook build

cp -r _book/* ../on_linebook/$book

cd ..

git add .

git commit -m 'update'

git push origin master

cd ~

envoy run book

下载包

1
composer require phpoffice/phpexcel

使用(实例化)

1
2
3
require "vendor/autoload.php";
use SimpleExcel\SimpleExcel; //当你的项目中没有用到命名空间不用写这一行
$obj = new PHPExcel();

##导出

操作sheet1

1
2
3
4
5
$obj->setactivesheetindex(0);
$obj->getActiveSheet()
->setCellValue('A'"a")
->setCellValue('B', 'b');
$obj->getActiveSheet()->setTitle('这是sheet1');

操作sheet2

1
2
3
4
5
$obpe->createSheet();
$obj->getActiveSheet()        
->setCellValue('A'"a")        
->setCellValue('B', 'b');
$obj->getActiveSheet()->setTitle('这是sheet2');

下载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$objPHPExcel->setActiveSheetIndex(0); // opend it on the first sheet
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type:application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="问吧数据.xlsx"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit();

###excel导入

我觉得这样要方便的多

1
return PHPExcel_IOFactory::load($file)->getActiveSheet()->toArray(null,true,true,true);