This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | >在编写 PHP 应用时经常需要处理日期和时间,使用[Carbon](http://github.com/briannesbitt/carbon) 会很方便 | |
| – 继承自 PHP[DateTime](http://www.php.net/manual/en/class.datetime.php) 类的 API 扩展,它使得处理日期和时间更加简单。 | |
| Laravel 中默认使用的时间处理类就是 Carbon。 | |
| #### 安装 | |
| ``` | |
| composer require nesbot/carbon //由于 Laravel 项目已默认安装了此包,所以不需要再次执行上面的命令。 | |
| ``` | |
| #### 使用 | |
| ``` | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | ### 简介 | |
| >laravel 的队列服务对各种不同的后台队列服务提供了统一的 API。队列允许你延迟执行消耗时间的任务,这样可以有效的降低请求响应的时间。这里做一个向所有用户发送系统消息的案例。 | |
| ##### 创建`notices`和`user_notice`表 | |
| ``` | |
| php artisan make:migration create_table_notice | |
| ``` | |
| ``` | |
| public funtion up() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | ### 步骤 | |
| ###### 定义策略类 | |
| ###### 注册策略类和模型关联 | |
| ###### 策略判断 | |
| #### 定义一个文章post的policy | |
| `/app/Policies`下会生产`PostPolicy.php`文件 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | **1.Unix域Socket通信** | |
| 之前简单介绍过Unix Domain Socket这种通信方式,参见:[Nginx+PHP-FPM的域Socket配置方法](http://blog.csdn.net/dc_726/article/details/9336193) | |
| Unix域Socket因为不走网络,的确可以提高Nginx和php-fpm通信的性能,但在高并发时会不稳定。 | |
| Nginx会频繁报错: | |
| connect() to unix:/dev/shm/php-fcgi.sock failed (11: Resource temporarily unavailable) while connecting to upstream | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | nginx的很简单就不记录了 | |
| #### 在阿里云官网购买证书 | |
| 1、选取证书类型 | |
|  | |
| 2、补全域名等信息,提交审核,通过后阿里云域名会得到记录值 | |
|  | |
| 3、下载证书 | |
|  | |
| #### 服务器配置 | |
| 1.启用有关SSL的模块,ssl.conf,ssl.load,socache_shmcb.load | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Sublime Text 3(以下简称 ST3)作为轻量级文本编辑器是很不错的,打开速度要比 VS Code 快不少,而且能够自动记住当前打开及尚未保存的文件。VS Code 中有一款通过 GitHub 的 GIST 在不同计算机同步设置与扩展的扩展`Settings Sync`,ST3中也有类似的扩展(但是只能同步设置),以下为安装与配置步骤: | |
| 打开 ST3,按住`Ctrl+Shift+P`,输入`Install`,并选择下图 1 中第一项。 | |
|  | |
| 图 1 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 以前尝试部署代码到服务器的方式有用到Github Hook或者ftp,但使用起来都有各自的缺陷,然后就发现了git hooks这个方法,查了一些资料再自己尝试过后,觉得还不错,记录下简单流程。 | |
| ### 在服务器初始化一个远程git仓库 | |
| ##### `git init` 和 `git init --bare` 的区别 | |
| 初始化出来的仓库是不一样的,前者初始化的是一个普通的仓库,其中 `.git` 文件夹是隐藏的,并且能看见该仓库下所有的源码。而后者初始化出来的仓库中的文件,就是 `.git` 中的文件夹,但不能像前者那样直接浏览或修改仓库中的代码。 | |
| ##### 使用 `git init --bare` 初始化一个远程仓库。 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 在`/usr/local/bin`目录下新建脚本`item2login.sh` | |
| ``` | |
| #!/usr/bin/expect | |
| set timeout 30 | |
| spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2] | |
| expect { | |
| "(yes/no)?" | |
| {send "yes\n";exp_continue} | |
| "password:" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | ###### 1、`mysql`加入环境变量 | |
| ``` | |
| ☁ ~ sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/local/bin/mysql | |
| ``` | |
| ###### 2、`apache`加入环境变量 | |
| ``` | |
| ☁ ~ sudo ln -s /Applications/MAMP/Library/bin/httpd /usr/local/bin/httpd | |
| ``` | |
| ###### 3、`php`加入环境变量 | |
| ``` | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #### 前提 | |
| 1.替换php源代码 | |
| > MAMP里面PHP源码是残缺的,所以需要自己下载PHP源码编译,因为php5.6和7.0都会用到,所以特将这两个版本的源码下载 | |
| php-5.6.链接: http://cn2.php.net/get/php-5.6.34.tar.gz/from/this/mirror | |
| php-7.0链接: http://cn2.php.net/get/php-7.0.28.tar.gz/from/this/mirror | |
| 进入php安装目录,并将原php重命名(以php7.0.27为例) | |
| ``` | |
| ☁ ~ cd /Applications/MAMP/bin/php/php7.0.27/include | |
| ☁ include mv php php.old |