LOADING

王思彤 发布的文章

新建github项目 并拉取到本地
本地执行composer init 初始化
打开composer.json编辑配置

{
    "name": "wangsitong/perfect-curl",
    "description": "easy curl for requests", 
    "type": "library", 
    "authors": [
        {
            "name": "wangsitong",
            "email": "512350703@qq.com"
        }
    ],
    "require": {
        "php": "^5.6|^7.0"
    },
    "minimum-stability": "dev",
    "license": "MIT",
    "keywords": [
        "curl",
        "wangsitong",
        "perfect-curl"
    ],
    "autoload": {
        "psr-4": {
            "PerfectCURL\\": "src/"
        }
    }
}

composer install 添加自动加载
WechatIMG1346.png

更新代码至github
使用github账号登录 https://packagist.org
点击submit
将你的项目的 github 地址 填到那个 input 中
点击check, 检测 composer.json 是否有误

异常处理:
Warning from https://mirrors.aliyun.com/composer: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See

或者提示找不到对应版本
composer self-update新包只支持composer2.0

https://github.com/wang-sitong/perfect-curl

https://packagist.org/packages/wangsitong/perfect-curl

composer require wangsitong/perfect-curl

linux下python版本升级
1、下载python版本

  wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz

2、编译,防止出现安装错误

  yum install gcc-c++ gcc make cmake zlib-devel bzip2-devel openssl-devel ncurse-devel -y

3、3.7版本需要一个新的包libffi-devel,安装此包之后再次进行编译安装即可

  yum install libffi-devel -y

4、解压与创建

  tar -zxvf Python-3.7.2.tar.xz
  #进入python3.7.2目录
  cd Python-3.7.2
  #创建目录
  mkdir -p /usr/local/python3
  #配置(指定安装目录)
  ./configure --prefix=/usr/local/python3 --enable-optimizations

5、编译与安装

  make && make install ,使用sudo命令时,记得make 和make install 都要有

6、更换版本,创建新版本Python3.7的软链接

  ln -s /usr/local/python3/bin/python3.7 /usr/bin/python

  先看下软链接,系统版本多的话,有可能会创建软链接失败,我就失败了。

7、查看是否成功

  python -V ,能看到新的版本证明成功

优先安装 uwsgi 用于接受nginx转发来的请求

pip3 install uwsgi

在项目目录下新建 uwsgi.ini

[uwsgi]
socket=127.0.0.1:9090 #接受nginx转发来的请求
chdir=/Applications/MAMP/htdocs/python_all_rivers #项目目录
module=reptlie.wsgi:application #wsgi文件目录
max-requests=5000 #最大请求数
daemonize=/var/log/yourproject.log #log文件地址 启动失败等日志都在里面

启动 uwsgi 切换到uwsgi.ini文件目录 载入配置方式启动

uwsgi --ini uwsgi.ini

查看是否启动

ps aux|grep uwsgi

root      295550  2.2  0.9  50184 38108 ?        S    14:48   0:00 uwsgi --ini reptlie/uwsgi.ini
root      295554  0.0  0.0   9032   728 pts/0    S+   14:48   0:00 grep --color=auto uwsgi

如需关闭 kill掉当前uwsgi pid

nginx配置


server {
            listen       80;
            server_name  python.allreviers.com;#你自己的域名

            location / {
                uwsgi_pass  127.0.0.1:9090;              #必须和uwsgi中的设置一致
                include  uwsgi_params;
                index  index.html index.htm;
                client_max_body_size 35m;
            }
        }

重启nginx即可
注:每次修改python文件后都需要kill掉 uwsgi 重新载入配置启动

配置 laravels
安装 swoole
安装 inotify
安装 laravels

  1. 安装 swoole
  2. http://pecl.php.net/get/swoole-4.4.19.tgz

tar -zxvf swoole-4.4.19.tgz
cd swoole-4.4.19
phpize
./configure
make && make install
注意 make install 需要 sudo 或使用 root 账号

查看 swoole 版本
php --ri swoole
重启 php
DEV 服务器使用 PHP7.3
/usr/local/php7.3/bin/phpize
./configure --with-php-config=/usr/local/php7.3/bin/php-config
添加扩展
sudo vim /usr/local/php7.3/etc/conf.d/modules.ini
启动 laravels
sudo -u www-data php7.3 artisan laravels restart

  1. 安装 inotify
  2. https://pecl.php.net/get/inotify-2.0.0.tgz

tar -zxvf inotify-2.0.0.tgz
cd inotify-2.0.0/
phpize
./configure
make && make install
注意 make install 需要 sudo 或使用 root 账号

查看 inotify 版本
php --ri inotify

  1. 安装 laravels
    使用 composer 安装

composer require "hhxsv5/laravel-s"
发布 laravels 配置文件

php artisan laravels publish
扩展阅读
swoole 官网
laravels Github

如果是crontab 执行 python selenium 的话 会出现一个因为环境变量引起的报错
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
解决方案是命令行改成

export DISPLAY=:0.0 && /usr/local/bin/python3.7 /srv/project/manage.py report >> /var/log/csj_login.log # django-cronjobs for priject

在Linux/Unix类操作系统上, DISPLAY用来设置将图形显示到何处. 直接登陆图形界面或者登陆命令行界面后使用startx启动图形, DISPLAY环境变量将自动设置为:0:0, 此时可以打开终端, 输出图形程序的名称(比如xclock)来启动程序, 图形将显示在本地窗口上

  1. 下载指定版本下文中以3.7.3为例
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
  1. 解压
tar zxvf Python-3.7.3.tgz
  1. 切换目录
cd Python-3.7.3
  1. 编译
./configure --with-ssl
make
sudo make install
–with-ssl必须加上,否则使用pip安装第三方包时,会引发ssl错误。导致无法使用
  1. 安装python依赖
sudo apt-get install python-dev python-setuptools python-pip python-smbus build-essential libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl libffi-dev
  1. 添加软连接 (方便区分不同版本)

添加python3的软链接

sudo ln -s /usr/local/bin/python3.7 /usr/bin/python3.7

添加 pip3 的软链接

sudo ln -s /usr/local/bin/pip3.7 /usr/bin/pip3.7

$toTime = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($oneSheet->getCell("A" . $j)->getValue());
$day = date('Y-m-d',$toTime);

结合方向 运算符 附加信息
无 clone new clone和new<
左 [ array()
右 ** 算术运算符
右 ++ -- ~ (int) (float) (string) (array) (object) (bool) @ 类型和递增/递减
无 instanceof 类型
右 ! 逻辑运算符
左 * / % 算术运算符
左 + - . 算术运算符和字符串运算符
左 << >> 位运算符
无 < <= > >= 比较运算符
无 == != === !== <> <=> 比较运算符
左 & 位运算符和引用<
左 ^ 位运算符
左 | 位运算符
左 && 逻辑运算符
左 || 逻辑运算符
左 ?? 比较运算符
左 ? : 三元运算符
右 = += -= = *= /= .= %= &= |= ^= <<= >>= 赋值运算符
左 and 逻辑运算符
左 xor 逻辑运算符
左 or 逻辑运算符

//示例代码
$status = $appAd->status ?? 0 == AppAdvertisement::APP_STATUS_SHOW && strpos($appAd->ad_type ?? '', 'splash') !== false ? 1 : 0;

今天在创建软连接的时候报了个语法错误
php artisan storage:link
完整错误信息如下
PHP Parse error: syntax error, unexpected '=' in /srv/test/server_dev/vendor/laravel/framework/src/Illuminate/Support/Arr.php on line 384
原因是因为这个服务器上有多个php版本,7.0以下的版本会出问题
php7.3 artisan storage:link
解决