php

Jupyter Notebook 安装 PHP 内核

普通安装 安装zmq扩展 官方的zmq已多年不维护了,并且在php7.4中报错,所以只能选择第三方的了 wget https://github.com/stijnvdb88/php-zmq/archive/refs/tags/v4.3.4.tar.gz tar -xvzf php-zmq-4.3.4.tar.gz mv php-zmq-4.3.4 /usr/src/php/ext/php-zmq #安装依赖 apt-get install -y libzmq3-dev #安装扩展 docker-php-ext-install php-zmq 安装Jupyter-PHP-Installe...

php 高精确度运算 - bc函数

项目中存储金额一般用int(分),或者decimal(8,2),如果用 decimal 会涉及到精度问题。比如:比较字符串0.01和0哪个大,结果是一样大,因为php会把0.01强转为0,这就不符合预期了 #两个任意精度的数字除法计算 bcdiv('200', '100', 2);//分转元,200/100 #比较两个任意精度的数字 bccomp($price, $step, 2) #两个任意精度数字的加法计算 bcadd($price, $step, 2) #两个任意精度数字的减法 bcsub($price, $step, 2) //将两个任意精度数字相乘 bcmul($sku->p...

PHPUnit 的使用

安装 PHP Archive (PHAR) wget -O phpunit https://phar.phpunit.de/phpunit-9.phar chmod +x phpunit root@php-fpm:/var/www/html# ./phpunit --version PHPUnit 9.5.27 by Sebastian Bergmann and contributors. 或者,Composer composer require --dev phpunit/phpunit ^9 root@php-fpm:/var/www/laravel-demo# ./vendor/bin/...

PHP PHPStan 的使用

安装 composer require --dev phpstan/phpstan 修改composer.json "scripts": { ... "stan": [ " php -d memory_limit=-1 vendor/bin/phpstan analyse app routes database config tests" ] }, 在项目根目录添加phpstan.neon配置文件 root@php-fpm:/var/www/laravel-demo# vi phpstan.neon 内...

PHP CS Fixer 的使用

安装 composer require --dev friendsofphp/php-cs-fixer 修改composer.json "scripts": { ... "cs-diff": [ "vendor/bin/php-cs-fixer fix --verbose --diff --dry-run" ], "cs-fix": [ "vendor/bin/php-cs-fixer fix --verbose --diff" ] }, 在项目根目录添加.php-...

PhpStorm 配置 Xdebug 3,及常见问题

做PHP开发也很多年了,Xdebug也配过很多次,但总觉得不是刚需,感觉有没有都行;另一方面它配置复杂(新方法很简单),每个项目都得配一遍(新方法也避免不了),并且在公司配完,回到家还得修改hosts 中的ip(新方法不需要)。种种原因,使用Xdebug的习惯并没有延续下来。直到我近日接触了yii2中的事件,比如: $config = [ 'components' => [ ... ], 'on beforeRequest' => function($event) { \yii\base\Event::on(\yii\db\BaseActiv...

yii2-queue队列的使用

安装 composer require yiisoft/yii2-queue 配置 //cat config/console.php return [ 'bootstrap' => [ 'queue', ], 'components' => [ 'redis' => [ 'class' => 'yii\redis\Connection', 'hostname' => 'docker-redis', 'port' => 6379, ...

laravel 调试工具

Laravel-debugbar 可以打印出每个请求执行的sql 安装 composer require barryvdh/laravel-debugbar 执行完即可,打开任一html页面(返回json的不行) 更详细的说明请参考:https://github.com/barryvdh/laravel-debugbar Artisan tail 实时显示系统日志 安装 composer require spatie/laravel-tail 执行完即可,常用命令 php artisan help tail php artisan tail 更详细的说明请参考:https://github...

yii debug和gii模块

开启 vi config/main.php if (YII_ENV_DEV) { $config['bootstrap'][] = 'debug'; $config['modules']['debug'] = [ 'class'=>'yii\debug\Module', 'allowedIPs'=>['*',], ]; $config['bootstrap'][] = 'gii'; $config['modules']['gii'] = [ 'class' => 'yii\gii\Mod...

The file or directory to be published does not exist: /var/www/yii-demo/vendor/yiisoft/yii2/gii/assets

报错内容 Invalid Argument – yii\base\InvalidArgumentException The file or directory to be published does not exist: /var/www/yii-demo/vendor/yiisoft/yii2/gii/assets 这错报的莫名其秒 我的目录结构 ├── api │   ├── config │   │   ├── bootstrap.php │   │   ├── main.php │   │   └── params.php │   ├── controllers │   │   ├...