brew update灾难来了!

我以前用brew 安装了多个php的版本,早上执行了brew update后php就用不了了

# openssl版本不对了
➔ /usr/local/opt/php@5.6/bin/php -v
dyld: Library not loaded: /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
  Referenced from: /usr/local/opt/php@5.6/bin/php
  Reason: image not found
[1]    16051 abort      /usr/local/opt/php@5.6/bin/php -v
# 把我的xdebug.so删掉了
➔ /usr/local/opt/php@7.2/bin/php -v
Failed loading /usr/local/opt/php@7.2/lib/php/20170718/xdebug.so:  dlopen(/usr/local/opt/php@7.2/lib/php/20170718/xdebug.so, 9): image not found
PHP 7.2.32 (cli) (built: Jul 10 2020 00:06:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.32, Copyright (c) 1999-2018, by Zend Technologies
# 又不知道缺了啥
➔ /usr/local/opt/php@7.4/bin/php -v
dyld: Library not loaded: /usr/local/opt/libffi/lib/libffi.6.dylib
  Referenced from: /usr/local/opt/php@7.4/bin/php
  Reason: image not found
[1]    16126 abort      /usr/local/opt/php@7.4/bin/php -v

我真的是太难了!!!

php5.6解决办法

其实可能我的电脑里已经有openssl@1.0,只是软链接指向变了,你也可以先直接修改软链接试试。

# 安装openssl@1.0
brew install rbenv/tap/openssl@1.0

# 修改symlink
ln -sf /usr/local/opt/openssl@1.0 /usr/local/opt/openssl

继续尝试:

➔ /usr/local/opt/php@5.6/bin/php -v
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.64.dylib
  Referenced from: /usr/local/opt/php@5.6/bin/php
  Reason: image not found
[1]    52151 abort      /usr/local/opt/php@5.6/bin/php -v

看看是否icu4c的老版本在不在吧:

➔ ll /usr/local/opt/icu4c
lrwxr-xr-x  1 jake  admin    20B Jul 22 11:36 /usr/local/opt/icu4c -> ../Cellar/icu4c/67.1

ll /usr/local/Cellar/icu4c/
total 0
drwxr-xr-x  12 jake  staff   384B Jun 28  2019 64.2
drwxr-xr-x  12 jake  staff   384B Jul 22 11:36 67.1

可能是64.2,试试:

ln -sf /usr/local/Cellar/icu4c/64.2 /usr/local/opt/icu4c

这一次php5.6就复活了!

➔ /usr/local/opt/php@5.6/bin/php -v                                                     
PHP 5.6.40 (cli) (built: Apr 23 2019 11:14:34) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans

php7.2那还能怎么办,选择原谅她啦

去这里:https://xdebug.org/wizard 把phpinfo的信息粘进去,重新build一个吧。

但是其实更严重的问题来了,php7.2依赖/usr/local/Cellar/icu4c/67.1,而php5.6依赖/usr/local/Cellar/icu4c/64.2,(php7.4却可以正常,神奇!)那只好把/usr/local/Cellar/icu4c/67.1的内容复制到/usr/local/Cellar/icu4c/64.2去吧:

# 复制以下两种文件似乎就可以了
➔ cp /usr/local/Cellar/icu4c/67.1/lib/*.67.1.dylib /usr/local/Cellar/icu4c/64.2/lib/
➔ cp /usr/local/Cellar/icu4c/67.1/lib/*.67.dylib /usr/local/Cellar/icu4c/64.2/lib/

➔ /usr/local/opt/php@7.2/bin/php -v
Failed loading /usr/local/opt/php@7.2/lib/php/20170718/xdebug.so:  dlopen(/usr/local/opt/php@7.2/lib/php/20170718/xdebug.so, 9): image not found
PHP 7.2.32 (cli) (built: Jul 10 2020 00:06:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.32, Copyright (c) 1999-2018, by Zend Technologies

可以了,稍后去把xdebug.so build出来。

php7.4如法炮制

➔ rm /usr/local/opt/libffi
➔ ln -s /usr/local/Cellar/libffi/3.2.1 /usr/local/opt/libffi

➔ /usr/local/opt/php@7.4/bin/php -v
PHP 7.4.4 (cli) (built: Mar 19 2020 20:12:27) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.4, Copyright (c), by Zend Technologies
    with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans

git mv使正确识别被修改名字的文件

有一个文件filename,由于在更名的同时也做了很大的变动,因此git无法识别这是一个被修改了名字的文件,正确识别应当这样:

➔ git status
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    renamed:    fileA -> fileB

现在是错误的识别了:

➔ git status
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   fileB
    deleted:    fileA

那怎么办呢?我是这么做的:

# 先unstage掉fileA,fileB
➔ git reset HEAD fileA fileB

# 用新文件生成老的文件
➔ cp fileB fileA

# 删除新文件
➔ rm fileB

# 使用git mv命令重命名
➔ git mv fileA fileB

# 最后看一下
➔ git status

git只add修改的和删除的文件

有时候我本地会写些tests测试用例文件,但是这些文件并不需要被提交,但是它们却有混杂在其他被修改的文件中,那该怎么办呢?

  1. 好的做法是修改.gitignore把这些文件排除开来
  2. 也可以通过git add -u app/ 这样,app目录下除了新增的文件没有被add,其他修改的和删除的都add进去了

另外如果你把一个不想提交的文件add了,可以使用git reset HEAD filename取消add。

我出的一组面试题

最近帮忙面试出的一组面试题,个人认为是比较基础的,如果你觉得题目不好, 欢迎提出来。供参考,如果你需要答案也欢迎联系我。

一、 PHP语法篇

  1. 写一个单例类。
  2. C => B => A 三个类,三个类中分别有静态方法m3、m2、m1,在B类的静态方法m中,分别调用C、B、A中的m3、m2、m1方法。
  3. 一个空数组,对应前端的一个对象,json_encode时,将其转换成{},而不是[]
  4. empty函数和isset函数的区别?
  5. 是否用过php7中的??
  6. 对psr规范是否了解,你觉得规范是否有不合理的地方

二、数据库篇

  1. having 和where的区别
  2. dinstinct的含义
  3. MySQL有哪些连接查询

三、Linux服务器篇

  1. 在centos上如何重启php-fpm
  2. 查看PHP安装的扩展,查看是否有安装mbstrig扩展
  3. crontab
  4. 给一个脚本增加所有用户可执行权限
  5. git 从分支A新建分支B,并同时切换到这个分支
  6. git 删除远程分支

Mac带窗口阴影截图

macbook有两个截图快捷键,一个是command+shift+3,用来截整个屏幕图,还有一个command+shift+4自由截图,自由截图时,可以按以下空格键变成窗口截图,窗口截图出来的图片就带有阴影了,默认截图都保存在桌面上(如果你只想截图到粘贴板中,而不是在桌面生成文件,可以尝试:control+cmd+shift+4)。
示例:

截屏2020-07-17 上午10.58.26

MySQL终端显示当前用户名、服务器、和数据库

MySQL终端默认是这样子的,比较简陋:

➔ mysql
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 150
Server version: 5.6.47-log Homebrew

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

觉得mysql>太简单了,我想让他显示更多的信息,就像平时我会用oh-my-zsh修改本地的shell那样,比如,这是我终端的提示符:

jake in Macintosh at Code/foo-poject on jake-v2.13 [!?$]
➔

可以显示当前用户名,目录,git版本等等信息。

方法很简单,设置一个环境变量即可:

export MYSQL_PS1="\u@\h [\d]> "

再次尝试:

➔ mysql
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 151
Server version: 5.6.47-log Homebrew

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@localhost [(none)]> use performancenet;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
root@localhost [performancenet]>

现在提示符部分变得丰富了😀,如果想永久生效,需要将export MYSQL_PS1="\u@\h [\d]> "这行命令加入到你的~/.bashrc(或者~/.zshrc)文件中。

SQL中的distinct关键字的正确用法

distinct 并不是一个函数,它只是一个修饰词,它的意思是过滤所有的重复返回行

因此以下语句:

select distinct(user.cellphone), user.points from user;

可能会返回重复的手机号的行,因为distinct 并不是跟(user.cellphone)结合的,它实际上是跟select结合的,将其修正为正确的写法:

select distinct user.cellphone, user.points from user;

这条语句的含义是返回user.cellphoneuser.points结合的唯一行,因此依然会有重复的手机号返回,以下语句则不会有重复的手机号返回,因为返回行总共只有一列:

select distinct user.cellphone from user;

如果想在返回唯一的手机号时,顺便携带points,则应当使用group by:

select user.cellphone, user.points from user group by user.cellphone;