Http request header坑记录

在开发公共API时,在请求头中(http request header)加入key secret来认证用户。
类似阿里云AccessKey AccessSecret。
header的key为MERCHANT_KEY MERCHANT_SECRET,PHP后端接收不到这些key的header。
查阅nginx资料发现,nginx默认设置会把含有下划线的key给忽略掉。
修改这些设置有两个方法:

1、修改nginx设置,underscores_in_headers 设置为 on

2、使用减号代替下划线,推荐这个方法

php 处理高精度计算函数

PHP 为任意精度数学计算提供了二进制计算器(Binary Calculator),它支持任意大小和精度的数字,以字符串形式描述

bcadd — 加法
bccomp — 比较
bcdiv — 相除
bcmod — 求余数
bcmul — 乘法
bcpow — 次方
bcpowmod — 先次方然后求余数
bcscale — 给所有函数设置小数位精度
bcsqrt — 求平方根
bcsub — 减法

涉及到钱的计算,还是以int存储,不容易出问题

PHPStorm激活码

77751S0VBA-eyJsaWNlbnNlSWQiOiI3Nzc1MVMwVkJBIiwibGljZW5zZWVOYW1lIjoi5b285bK4IHNvZnR3YXJlMiIsImFzc2lnbmVlTmFtZSI6IiIsImFzc2lnbmVlRW1haWwiOiIiLCJsaWNlbnNlUmVzdHJpY3Rpb24iOiJGb3IgZWR1Y2F0aW9uYWwgdXNlIG9ubHkiLCJjaGVja0NvbmN1cnJlbnRVc2UiOmZhbHNlLCJwcm9kdWN0cyI6W3siY29kZSI6IklJIiwicGFpZFVwVG8iOiIyMDE5LTAxLTA1In0seyJjb2RlIjoiUlMwIiwicGFpZFVwVG8iOiIyMDE5LTAxLTA1In0seyJjb2RlIjoiV1MiLCJwYWlkVXBUbyI6IjIwMTktMDEtMDUifSx7ImNvZGUiOiJSRCIsInBhaWRVcFRvIjoiMjAxOS0wMS0wNSJ9LHsiY29kZSI6IlJDIiwicGFpZFVwVG8iOiIyMDE5LTAxLTA1In0seyJjb2RlIjoiREMiLCJwYWlkVXBUbyI6IjIwMTktMDEtMDUifSx7ImNvZGUiOiJEQiIsInBhaWRVcFRvIjoiMjAxOS0wMS0wNSJ9LHsiY29kZSI6IlJNIiwicGFpZFVwVG8iOi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Rnt1kA9N2Qachl+2yBfaqUqr8h7Z2gsx5LcIf5kYNsqJ0GavXTVyWh7PYiKX4bs354ZQLUwwa/cG++2+wNWP+HtBhVxMRNTdVhSm38AknZlD+PTAsWGu9GyLmhti2EnVwGybSD2Dxmhxk3IPCkhKAK+pl0eWYGZWG3tJ9mZ7SowcXLWDFAk0lRJnKGFMTggrWjV8GYpw5bq23VmIqqDLgkNzuoog==

 

有效期至 2019-01-05

php 数组 类对象 值传递 引用传递 区别

php中,数组是当一个普通变量,值传递是要一个实参的一个拷贝副本,跟实参无关,引用传递后可以改变实参的值

而类的对象是无论值传递和引用传递都是引用传递,是对对象的引用,都会改变实参的值

结合clone函数就不难理解PHP对对象的传递是类似指针传递

对象的值传递和引用传递在特定场景下面是有区别的

PHPExcel 行号、数字互转

$a = PHPExcel_Cell::columnIndexFromString(‘A’);

// $a = 1;

$b = PHPExcel_Cell::stringFromColumnIndex(0);

// $b = ‘A’;

注意,这两个方法的起始数字 一个是1 一个是0

laravel eloquent relation manyToMany

User Model 和 Role Model 多对多关系示例

其中 role_user 是枢纽表表名

public function roles()
{
    return $this->belongsToMany(Role::class, 'role_user', 'user_id', 'role_id');
}

xdebug最高性能配置

笔者写比较复杂的逻辑的时候,喜欢使用xdebug来单步调试每一行代码。从网络上抄来的参考配置设置好了之后,发现php在执行之前需要等待很久时间。经过一段时间研究,修改xdebug配置就能跳过那段10秒钟左右的等待时间。配置如下:

 

zend_extension=php_xdebug-2.4.1-7.0-vc14-nts.dll
[XDebug]
xdebug.profiler_append=Off
xdebug.profiler_enable=Off
xdebug.auto_trace=Off
xdebug.collect_params=Off
xdebug.collect_return=Off
xdebug.profiler_enable=Off
xdebug.profiler_enable_trigger = Off
xdebug.profiler_output_dir="D:\phpStudy\tmp\xdebug"
xdebug.trace_output_dir="D:\phpStudy\tmp\xdebug"
xdebug.profiler_output_name="cachegrind.out.%t.%p"
xdebug.remote_enable=1
xdebug.remote_handler="dbgp"
xdebug.remote_host="127.0.0.1"
xdebug.remote_port=9001
xdebug.idekey=phpstorm

php闭包

php的闭包(Closure)也就是匿名函数。是PHP5.3引入的。

闭包的语法很简单,需要注意的关键字就只有use,use意思是连接闭包和外界变量。

1
2
3
$a = function() use($b) {
}

继续阅读“php闭包”