1、php格式化json的函数,json_encode($value, $options);php
2个比较经常使用的参数:css
一、JSON_UNESCAPED_UNICODE(中文不转为unicode,对应的数字256)html
$array = ['a'=>'床前明月光/', 'b'=>'疑是地上霜', 'c'=>'举头望明月', 'd'=>'低头思故乡']; $arrayJson = json_encode($array, JSON_UNESCAPED_UNICODE); var_dump($arrayJson); // 结果 string(91) "{"a":"床前明月光\/","b":"疑是地上霜","c":"举头望明月","d":"低头思故乡"}"
二、JSON_UNESCAPED_SLASHES(不转义反斜杠,对应的数字64)mysql
$array = ['a'=>'床前明月光/', 'b'=>'疑是地上霜', 'c'=>'举头望明月', 'd'=>'低头思故乡']; $arrayJson = json_encode($array, JSON_UNESCAPED_SLASHES); var_dump($arrayJson); // 结果 string(150) "{"a":"\u5e8a\u524d\u660e\u6708\u5149/","b":"\u7591\u662f\u5730\u4e0a\u971c","c":"\u4e3e\u5934\u671b\u660e\u6708","d":"\u4f4e\u5934\u601d\u6545\u4e61"}"
2个参数同时使用:linux
JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES = 320git
使用方法:json_encode($array, 320);web
$array = ['a'=>'床前明月光/', 'b'=>'疑是地上霜', 'c'=>'举头望明月', 'd'=>'低头思故乡']; $arrayJson = json_encode($array, 320); var_dump($arrayJson); // 结果 string(90) "{"a":"床前明月光/","b":"疑是地上霜","c":"举头望明月","d":"低头思故乡"}"
2、php资源路径处理ajax
1.[http|https]+host+port 从当前url读取,不要硬编码
2.储存资源路径用相对地址uri,对外接口返回资源绝对url【$_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . $row['photo']】其中$_SERVER['HTTP_HOST'] = $_SERVER['SERVER_NAME']+$_SERVER['PORT']redis
3、xml字符破影响vim编辑器对php syntax问题
算法
$xml = "<?xml version=\"1.0\" encoding=\"{$encoding}\"?>"; 解决办法: $xml = '<?xml version="1.0" encoding="{$encoding}"?'.'>';
4、php获取sql执行错误信息
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
5、linux 软硬连接的区别和应用场景
硬连接等于cp -p加同步更新。
软连接像快捷方式,方便咱们打开源文件,这一点在windows中深有体会,那硬连接有哪些应用呢?
在多用户的操做系统里,你写一个脚本,程序等,没有完成,保存后等下次有时间继续写,可是其余用户有可能将你未写完的东西当成垃圾清理掉,这时,你对你的程序,脚本等作一个硬连接,利用硬连接的同步更新,就能够方式,别人误删你的源文件了
详情阅读:https://blog.csdn.net/gao_zhennan/article/details/79127232
6、shell编程知识
kill -TERM `cat /usr/local/apache2/logs/httpd.pid`
elasticsearchID=$(ps aux|grep elasticsearch|grep -v "grep"|awk '{print $2}') echo "elasticsearch的pid为$elasticsearchID" if [[ $elasticsearchID ]] # 这里判断elasticsearch进程是否存在 then echo "elasticsearch正常状态" else echo "elasticsearchID没有启动" systemctl restart elasticsearch fi
7、php5.6.30编译安装参数
./configure --prefix=/usr/local/php --with-apxs2=/usr/bin/apxs --with-config-file-scan-dir=/etc/php.d --with-config-file-path=/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-tidy --enable-zip --enable-soap --with-gettext --with-xsl --with-pear --enable-opcache --enable-fileinfo --enable-wddx --enable-static --enable-sysvshm --enable-sysvmsg --enable-shared --enable-apc --enable-apc-mmap --enable-apu
特别说明的几点:
一、--with-pear //安装pear,方便往后安全须要加装的扩展,peal安装扩展,详细阅读:https://www.php.net/manual/zh/install.pecl.php
二、--enable-maintainer-zts //线程安全,该参数设置php线程安装,有时候是不须要的,nts
三、--with-config-file-scan-dir=/etc/php.d --with-config-file-path=/etc //指定php.ini位置和扩展模块配置文件目录,指定/etc/php.ini。php-cli和web模式使用的php.ini路径就一致了,php --ini php -c "/etc/php.ini"
四、--with-apxs2=/usr/bin/apxs //指定php做为apache2的模块安装运行,不与php-fpm同时使用
8、linux composer和docker安装
linux composer安装 curl -sS https://getcomposer.org/installer | php linux docker安装 wget -qO- https://get.docker.com | sh
特别说明:
web目录源码备份不要出现.bak .ini等文件,由于curl -sS http://xxxx/xxx.bak会直接暴露源码,是配置文件备份,就更危险了
9、mysql sql查询数据导出
mysql> SHOW VARIABLES LIKE '%secure_file_priv%';
+------------------+-----------------------+
| Variable_name | Value |
+------------------+-----------------------+
| secure_file_priv | /var/lib/mysql-files/ |
+------------------+-----------------------+
1 row in set (0.00 sec)
select * from user into outfile '/var/lib/mysql-files/test.xls';
详细阅读:https://www.cnblogs.com/lfxiao/p/9378763.html
11、mysql事务
set autocommit 1|0 1 mysql默认为1,表示开启自动提交。 0 表示没有开启自动提交 若是没有开启自动提交,当前session1所连接的mysql的全部操做都会当成一个事务直到你输入rollback/commit; 当前事务才算结束。当前事务结束前新的mysql链接时没法读取到任何session1的操做的结果的。 若是开起了,mysql会把每一个sql语句当成一个事务而后自动的commit。 固然不管开启与否,start transaction commit|rollback都是独立的事务。
12、curl post
curl -d "desc=刷卡测试样例-支付&fee=2&barcode=134709973417403352" "http://api.syhuo.net/testpay/pay?pay_method=wxpay"
十3、捕捉json_encode、json_decode错误
json_decode 返回NULL 用json_last_error()
十4、jquey ajax同步异步
async: true, //异步,有时须要显示指定异步请求,否则beforeSend里设置效果有些出不来。
十5、redis服务参数优化:
maxmemory-samples 5
maxmemory-samples在redis-3.0.0中的默认配置为5,若是增长,会提升LRU或TTL的精准度,redis做者测试的结果是当这个配置为10时已经很是接近全量LRU的精准度了,而且增长maxmemory-samples会致使在主动清理时消耗更多的CPU时间
maxmemory
没有带单位尾巴的为字节数,以B结尾的表示相应的大小。但须要注意KB和K、MB和M、GB和G是不一样的,如1K表示1000字节,而1KB则为1024字节。若是maxmemory值为0,表示不作限制
过时策略
maxmemory_policy
一、volatile-lru:只对设置了过时时间的key进行LRU(默认值)
二、allkeys-lru : 删除lru算法的key
三、volatile-random:随机删除即将过时key
四、allkeys-random:随机删除
五、volatile-ttl : 删除即将过时的
六、noeviction : 永不过时,返回错误
redis 中的默认的过时策略是 volatile-lru
十6、php-cli执行测试语句或文件
php -r "new PDO('mysql:host=127.0.0.1;dbname=db_php', 'root', '');" php -f ./phpinfo.php |grep -i 'pdo_mysql.default_socket'
十7、curl就是linux系统开发人员的浏览器,功能十分强大
-k Allow connections to SSL sites without certs
-i, --include Include protocol headers in the output
-H, --header LINE Pass custom header LINE to server (H)
-X, --request COMMAND Specify request command to use
-S, --show-error Show error. With -s, make curl show errors when they occur
-s, --silent Silent mode (don't output anything)
-d, --data DATA HTTP POST data (H) HTTP POST方式传送数据
https: curl -X POST -k -H 'Content-Type: application/json' -i 'https://upgradeapi.andshi.cn:11443/oauth2/access_token.json' --data '{ "client_id": "shengyihuo", "client_secret": "bf579895ae4e5964bb4e78a09c01551b", "grant_type": "client_credentials" }' http: curl -X POST -H 'Content-Type: application/json' -i 'http://upgradeapi.andshi.cn:8008/oauth2/access_token.json' --data '{ "client_id": "shengyihuo", "client_secret": "bf579895ae4e5964bb4e78a09c01551b", "grant_type": "client_credentials" }' {"access_token":"26b90887f4878b020629764692b36bbd9f443508","expires_in":3600,"token_type":"Bearer","scope":null} 上传 curl -X POST -H 'Content-Type: application/json' -i 'http://upgradeapi.andshi.cn:8008/remote/upload_data.json' --data '{ "client_id": "shengyihuo", "access_token": "26b90887f4878b020629764692b36bbd9f443508", "sn": "18088004400001", "data": "{\"fingerprint\":\"0\",\"iccard\":\"0\",\"idcard\":\"0\",\"ir\":\"0\",\"magneticcard\":\"0\",\"moneybox\":\"0\",\"nfc\":\"0\",\"ocr\":\"0\",\"pinpad\":\"0\",\"printer\":\"0\",\"psam\":\"0\",\"qrcode\":\"0\",\"scangun\":\"0\"}" }' 下达 curl -X POST -H 'Content-Type: application/json' -i 'http://upgradeapi.andshi.cn:8008/remote/get_data.json' --data '{ "client_id": "shengyihuo", "access_token": "26b90887f4878b020629764692b36bbd9f443508", "sn": "18088004400001" }'
p
curl -d "desc=刷卡测试样例-支付&fee=1&barcode=134578732239251989" "http://api.syhuo.net/testpay/pay?pay_method=wxpay"
十8、解决项目生产,灰度、测试、开发多套环境不一样加载各自环境配置文件的奇淫技巧
肯定apache加载了env_module、setenvif_module模块
[root@VM_58_118_centos ~]# apachectl -t -D DUMP_MODULES|grep env env_module (shared) setenvif_module (shared)
apache站点设置环境变量
<VirtualHost *:80> ServerAdmin "master@master.com" DocumentRoot "/data/www/syhuo.net" #ServerName www.syhuo.net ServerName www.zhinengyingjian.work SetEnv RUN_MODE production <FilesMatch "\.(ico|gif|jpg|png|bmp|swf|js|css|eot)"> SetEnv IMAGE 1 </FilesMatch> ErrorLog "| /usr/sbin/rotatelogs /data/httpd/logs/www.syhuo.net-error-%Y%m%d.log 86400" #CustomLog "| /usr/sbin/rotatelogs /data/httpd/logs/www.syhuo.net-access-%y%m%d.log 86400" common env=!IMAGE <Directory "/"> #Options Indexes FollowSymLinks Options FollowSymLinks AllowOverride All #AllowOverride None #Order Allow, Deny Order Deny,Allow Require all granted </Directory> <Directory ".git"> Deny from All Require all denied </Directory> </VirtualHost>
php读取环境变量,加载对应的配置文件
<?php print_r($_SERVER['RUN_MODE']); //输出production