1064

MacOS修改终端日期显示格式

前言

MacOS下修改终端日期格式与Linux不同,主要原因是MacOS下的ls命令与Linux的ls程序不同,所以设置方式不一样。

Linux修改终端日期格式

编辑 .bashrc 或 .zshrc文件

vi ~/.zshrc

添加如下内容:

export TIME_STYLE= ' +%Y-%m-%d %H:%M:%S '
1011

MacOS查看端口命令

netstat 命令

例如:查看所有监听的端口

netstat -nat |grep LISTEN

例如:查看9000端口

netstat -nat |grep 9000
# 示例输出
tcp4       0      0  127.0.0.1.9000         *.*                    LISTEN
1268

MacOS使用brew services 和 launchctl管理服务

前言

MacOS可以使用launchctl命令管理服务,也可以使用brew services

brew services 相比 launchctl,操作更简化,更加类似 Centos 的 systemd 命令。

brew services常用命令

启动、停止服务

例如:启动nginx

brew services start nginx

例如:停止php-fpm

brew services stop php
1061

MacOS使用Brew安装PHP和PHP扩展的安装

安装PHP

直接使用brew命令安装即可

brew install php

安装指定版本

brew install php@7.2

安装PHP扩展

MacOS下使用pecl安装PHP扩展

查看pecl

pecl version
581

PHP CLI启动多进程,并实现进程间通信

方式一:msg_get_queue实现

$key = ftok(__FILE__, 'a');
$queue = msg_get_queue($key);
$pidList = [];
$socketList = [];

for ($i = 1; $i <= 2; $i++) {
    $taskPid = pcntl_fork();
    if ($taskPid == -1) {
        die("[父进程]child{$i}创建失败");
    } elseif ($taskPid) {
        $pidList[$i] = $taskPid;
        echo "[父进程]child{$i}创建成功,子进程ID:{$taskPid}". PHP_EOL;
    } else {
        //子进程
        while (true) {
            msg_receive($queue, 1, $type, 1024, $msg);
            if ($msg) {
                echo "[子进程@child{$i}]收到消息:{$msg}";
            }
            usleep(50);
        }
    }
}

//父进程循环
while (true) {
    msg_send($queue, 1, ['from'=>'father','text'=>"Hi child,I'm father."]);
    sleep(3);
}