Write the Code. Change the World.

分类目录
8月 18

params 的字符串和 array 的转换

$array = ['gender' => 1, 'target' => 2, 'region' => 310100];

$paramsStr = $str = http_build_query($array);

var_dump($paramsStr);

parse_str($paramsStr, $paramsArr);

var_dump($paramsArr);

在线测试:https://www.json.cn/runcode/run_php/

输出结果

string(31) "gender=1&target=2®ion=310100"
array(3) {
  ["gender"]=>
  string(1) "1"
  ["target"]=>
  string(1) "2"
  ["region"]=>
  string(6) "310100"
}
8月 09

一个项目,一般不仅有 mysql 数据库,还会有 redis、mongodb 等数据库。那 下边记录下 laravel 中配置和使用 mongodb。

准备

安装 mongdb 和 mongdb 扩展

# 最快最简单的安装方式
pecl install mongodb

# 在 php.ini 中配置 mongodb

# 先找到 php.ini 的位置
php -i | grep php.ini

# 开始配置
vim php.ini
# 加入 extension=mongodb.so

# 重启
/etc/init.d/php-fpm restart

# 看看扩展
php -m |grep mongodb

项目中

https://github.com/jenssegers/laravel-mongodb

composer require jenssegers/mongodb

在 config/database.php 的 connections 中配置

        'mongodb' => [
            'driver' => 'mongodb',
            'host' => env('MONGO_DB_HOST', '127.0.0.1'),
            'port' => env('MONGO_DB_PORT', 27017),
            'database' => env('MONGO_DB_DATABASE', 'homestead'),
            'username' => env('MONGO_DB_USERNAME', 'homestead'),
            'password' => env('MONGO_DB_PASSWORD', 'secret'),
            'options' => [
                'database' => env('MONGO_DB_AUTHENTICATION_DATABASE', 'admin'), // required with Mongo 3+
            ],
        ]

        # 或
        'mongodb' => [
            'driver' => 'mongodb',
            'dsn' => env('MONGO_DB_DSN'),
            'database' => env('MONGO_DB_DATABASE', 'homestead'),
        ],

在 .env 中进行 MONGO_DB_DSN 和 MONGO_DB_DATABASE 配置。

使用

这里,我既使用 mysql, 也使用 mongodb。并且都使用 ORM。 mysql 是默认驱动方式。

php artisan make:model Moment

### 编辑 App\Models\Moment ,如下
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Jenssegers\Mongodb\Eloquent\Model;

class Moment extends Model
{
    use HasFactory;

    // 驱动
    protected $connection = 'mongodb';

   // 表
    protected $collection = 'detail.idc';
}

用 tinker 试试:

php artisan tinker;

use App\Models\Moment;
Moment::first();

参考

https://www.bubaijun.com/page.php?id=230

7月 19

As you may know, this year we updated the Laravel release cycle to include one major release per year. Previously, we released two major versions per year.

These release changes would typically indicate that a Laravel 9 release is due in September of this year. However, as you may know, Laravel uses a variety of community-driven packages as well as nine Symfony components for a number of features within the framework. Symfony 6.0 is due for release in November. For that reason, we are choosing to delay the Laravel 9.0 release until January 2022.

By delaying the release, we can upgrade our underlying Symfony components to Symfony 6.0 without being forced to wait until September 2022 to perform this upgrade. In addition, this better positions us for future releases as our yearly releases will always take place two months after Symfony's releases. This means that the upcoming Laravel release schedule will look as follows:

Laravel 9.0: January 2022
Laravel 10.0: January 2023
Laravel 11.0: January 2024
We are continuing to deliver exciting new improvements to the Laravel 8.x release series. In fact, we have been able to ship a variety of amazing new features without needing a major release, including parallel testing, model broadcasting improvements, and more. We look forward to shipping even more wonderful improvements to you soon!

原文

https://blog.laravel.com/laravel-9-release-date

7月 16

步骤

  1. 新建空目录。 zz.com
  2. 进 zz.com。 新建 composer.json 文件。并填充内容。
{
  "require": {
    "jonnyw/php-phantomjs": "4.*"
  }
}
  1. 执行 composer.update 。
  2. 建立 git 和 .gitignore 忽略文件
git init
.gitignore 中填充 /vendor
git add .
git commit -m '新建 composer.json 文件,配置安装 jonnyw/php-phantomjs'
  1. 新建路由以及配置自动加载。

参考

https://learnku.com/laravel/t/3590/php-crawls-the-page-that-needs-to-run-js-run-js-grabing-web-page-with-php-while

https://blog.junphp.com/details/391.jsp

https://blog.csdn.net/luyaran/article/details/53836486

7月 09

准备

https://github.com/FriendsOfPHP/Goutte

https://github.com/guzzle/guzzle

https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html

安装

composer require fabpot/goutte

composer require guzzlehttp/guzzle

试试

先看看 goutte

use Goutte\Client;

$client = new Client();
$crawler = $client->request('GET', 'https://www.yuepaibao.com/moments');
$crawler->filter('.content span')->each(function ($node) {
print $node->text()."\n";
});

**再看看 GuzzleHttp **

use GuzzleHttp\Client as GoutteClient;
use GuzzleHttp\Psr7\Request as GuzzleRequest;

$url = 'https://www.hao123.com';
$request = new GuzzleRequest('GET', $url);
$client = new GoutteClient();
$response = $client->send($request, ['timeout' => 5]);
$content = $response->getBody()->getContents();
echo $content;

特殊

https://learnku.com/laravel/t/3590/php-crawls-the-page-that-needs-to-run-js-run-js-grabing-web-page-with-php-while

6月 03

mysql 事务里,没有使用 commit。导致该资源被长期占用,其他事务在抢占该资源时,因上一个事务的锁而导致抢占失败。

处理

方法一
- 查看事物表,找出被锁线程的id:SELECT * FROM information_schema.INNODB_TRX;
- 根据 id(trx_mysql_thread_id),kill掉被锁住的线程:kill 121212

方法二
- 执行MySQL命令:SHOW FULL PROCESSLIST; 找到被锁住的线程ID
- 根据id,kill掉被锁住的线程:kill 4

5月 21

一套完善编码规范很重要。 php-cs-fixer 可一键把代码格式化为 PSR-2 标准。 php-cs-fixer 可单独使用,也可以结合编辑器使用。

github: https://github.com/FriendsOfPHP/PHP-CS-Fixer

操作一波

下载并设置权限

cd /usr/local/bin

wget https://cs.symfony.com/download/php-cs-fixer-v2.phar -O php-cs-fixer 

chmod +x php-cs-fixer

使用

# 格式化当前目录下代码 
php-cs-fixer fix .
3月 23

composer 安装包的时候,可能出现 memory 不足问题处理。

error

PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223

解决步骤

  • 使用 composer -h 找到 composer 的位置.
  • 开始安装
php -d memory_limit=-1 /usr/local/bin/composer require laravel/sanctum
2月 02

直接开始

# 方式一
sudo pecl channel-update pecl.php.net

sudo pecl install swoole

# 方式二
# 官网 https://wiki.swoole.com/#/environment
# pecl https://pecl.php.net/package/swoole
cd /usr/local/src
sudo wget https://pecl.php.net/get/swoole-4.6.2.tgz
sudo tar -xzvf swoole-4.6.2.tgz
cd swoole-4.6.2
sudo phpize

sudo ./configure \
--enable-openssl \
--enable-http2 

# 支持更多可以看文档
./configure \
--enable-openssl \
--enable-http2 \
--enable-swoole-json \
--enable-swoole-curl

sudo make && make install
sudo make test

# 找到扩展存放位置
php -i|grep extension_dir
 /usr/lib/php/20190902
 sudo cp /usr/local/src/swoole-4.6.2/modules/swoole.so ./swoole.so
 # 然后安装下边的方式配置和重启即可。

# 找 php 版本,发现是 7.4
php -v

sudo vim /etc/php/7.4/mods-available/swoole.ini

# php 扩展安装位置
php -i|grep extension_dir

# 写入下边内容
extension=swoole.so

# 创建软链
cd /etc/php/7.4/cli/conf.d
sudo ln -s /etc/php/7.4/mods-available/swoole.ini ./20-swoole.ini

# 重启
sudo service php7.4-fpm restart

# 查看 
php --ri swoole
php -i |grep swoole
12月 24

过程

vagrant box remove laravel/homestead

vagrant destroy

# virtualbox 自带 uninstall 
# 删除 vagrant 

mac 安装的软件

  • Chrome
  • iterm2
  • 迅雷
  • vscode
  • 微信
  • Geph
  • 百度云盘
  • ForkLift
  • HbuilderX
  • 腾讯课堂
  • Adobe Photoshop
  • Adobe InDesign
  • Adobe Lightroom Classic
  • Adobe Preme
  • Adobe II
  • ezip
  • 爱奇艺
  • 钉钉
  • 达芬奇
  • Screenium 视频截图
  • MacClean
  • Navicat Premium
  • rdm
  • Postman
  • 微信开发者工具
  • 腾讯视频
  • qq音乐
  • QQ
  • Sequel Pro
  • 微信支付商户证书工具
  • 百度小程序开发者工具
  • Novavi PDF Editor2 这个蛮好用的 pdf 可以编辑 pdf
  • 有道云笔记
  • 花间
  • mac office2019

mac ntfs 工具

https://blog.csdn.net/huajian121/article/details/108835602