分类目录归档:后端

mysql 5.7 group by

mysql 报错

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #6 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘field_name’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

原因

mysql 5.7 sql_group 默认按sql标准了
可以设置sql_mode 去掉
SELECT @@GLOBAL.sql_mode;
SELECT @@SESSION.sql_mode;
set @@GLOBAL.sql_mode=’STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’;
set @@SESSION.sql_mode=’STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’;

echart Y 轴 最大值计算

max : function (value) {
var num = Math.ceil(value.max / 4);
var len = (” + num).length – 1;
var num2 = Math.pow(10,len);
var num3 = Math.round(num / num2) * num2;
return num3 * 5;
}

Lnmp .user.ini open_basedir

 

lnmp

open_baseidr 限制php的执行目录,文件上传不了,没权限写文件。

 

lnmp 在 nginx 中设置了 open_basedir 变量 ,致使 在目录中设置的.user.ini 的open_basedir 无效

 

fastcgi.conf:fastcgi_param PHP_ADMIN_VALUE “open_basedir=$document_root/:/tmp/:/proc/”;

 

.user.ini

open_basedir=/home/wwwroot/:/tmp/:/proc/

 

 

 

Using imagemagick montage with PHP

<?php

$sources = array(
‘red.png’,
‘green.png’,
‘blue.png’,
‘orange.png’
);

$stack = new Imagick();
foreach( $sources as $source ) {
$stack->addImage(new Imagick($source));
}

$montage = $stack->montageImage(new ImagickDraw(), ‘2×2’, ‘500×300’, 0, ‘0’);
$montage->writeImage(‘out.png’);

 

try{

$im = new Imagick();
//$imgs = glob(‘img/*-.jpg’);
foreach( $local_img as $source ) {
$thumb = new Imagick($source);
$thumb->thumbnailImage(600,0);
$im->addImage($thumb);

}
$out = $im->montageImage(new ImagickDraw(),’1x’,’600+0+0′,0,’0′);

$out->writeImage($new_img);
$im->destroy();
$out->destroy();

return str_replace(ABSPATH,home_url(‘/’),$new_img);
}catch (Exception $ex){
//print_r($ex);

$this->info(“Exception”,$ex->getMessage(),$ex->getCode());
}

 

size General description (actual behavior can vary for different options and settings)
scale% Height and width both scaled by specified percentage.
scale-x%xscale-y% Height and width individually scaled by specified percentages. (Only one % symbol needed.)
width Width given, height automagically selected to preserve aspect ratio.
xheight Height given, width automagically selected to preserve aspect ratio.
widthxheight Maximum values of height and width given, aspect ratio preserved.
widthxheight^ Minimum values of width and height given, aspect ratio preserved.
widthxheight! Width and height emphatically given, original aspect ratio ignored.
widthxheight> Shrinks an image with dimension(s) larger than the corresponding width and/or height argument(s).
widthxheight< Enlarges an image with dimension(s) smaller than the corresponding width and/or heightargument(s).
area@ Resize image to have specified area in pixels. Aspect ratio is preserved.
{size}{offset} Specifying the offset (default is +0+0). Below, {size} refers to any of the forms above.
{size}{+-}x{+-}y Horizontal and vertical offsets x and y, specified in pixels. Signs are required for both. Offsets are affected by ‑gravity setting. Offsets are not affected by % or other size operators.

imagemagick montage usage

imagemagick command geometry

Linux 终端日志打印输出问题

程序后台执行:
在命令最后加上&符号,表示让这个进程到后台去执行,这样立刻返回到提示符状态,我们可以接着做下面的事。如:command &

退出终端仍然执行:

信息输出处理:

但此时如果这个进程有输出,还是会显示出来,这又会干扰到我们的shell窗口。所以可以考虑把标准输出重定向到某个文件去,如:command >output &

现在清净了。但有时我们会发现后台运行的进程出错了,我们希望把错误信息也保存起来。那就用到了linux中默认定义两个变量:1指标准输出;2指错误输出,所以写成这样:command 1>output 2>error & ,正常的输出在output文件里,错误的输出在error文件里。这里也等同于command >output 2>error &

有时候只想保留一种,另外一个既不输出又不保存,那就用到这个设备/dev/null,所以忽略错误输出:command 1>output 2>/dev/null & ;忽略标准输出:command 1>/dev/null 2>error &;忽略全部输出: command 1>/dev/null 2>/dev/null

1,2两种信息之间还可以进行重定向,所以这种:command 1>output 2>&1 & 表示错误输出也重定向回标准输出,即两种信息都保存到output里。那干嘛不写成command 1>output 2>output & 呢?答案是这样不行,别看都输出到/dev/null可以,但如果写成相同的文件名会导致冲突,所以如果想同时保留只能是上面的写法;同理:忽略全部输出还可以写成: command >/dev/null 2>&1 &

这样的文件输出,每次运行会覆盖现有的文件,如果我们希望追加而不是覆盖,那么就用>>符号,这样命令就是: command 1>>log 2>>error &

基本上参数的各种写法都在这里了,但有个问题。这种“后台”进程在shell一直打开的情况下是没有问题的,如果我们关了shell窗口甚至退出ssh登录或vnc登录,那么进程自动就结束了。所以如果想退出窗口乃至退出登录仍然保持程序运行,再加上nohup,形如:nohup command 1>output 2>&1 &

rsync 常用形式及参数

rsync的命令格式可以为以下六种:

rsync [OPTION]… SRC DEST
rsync [OPTION]… SRC [USER@]HOST:DEST
rsync [OPTION]… [USER@]HOST:SRC DEST
rsync [OPTION]… [USER@]HOST::SRC DEST
rsync [OPTION]… SRC [USER@]HOST::DEST
rsync [OPTION]… rsync://[USER@]HOST[:PORT]/SRC [DEST]
对应于以上六种命令格式,rsync有六种不同的工作模式:
1)拷贝本地文件。当SRC和DES路径信息都不包含有单个冒号”:”分隔符时就启动这种工作模式。如:rsync -a /data /backup
2)使用一个远程shell程序(如rsh、ssh)来实现将本地机器的内容拷贝到远程机器。当DST路径地址包含单个冒号”:”分隔符时启动该模式。如:rsync -avz *.c foo:src
3)使用一个远程shell程序(如rsh、ssh)来实现将远程机器的内容拷贝到本地机器。当SRC地址路径包含单个冒号”:”分隔符时启动该模式。如:rsync -avz foo:src/bar /data
4)从远程rsync服务器中拷贝文件到本地机。当SRC路径信息包含”::”分隔符时启动该模式。如:rsync -av root@172.16.78.192::www /databack
5)从本地机器拷贝文件到远程rsync服务器中。当DST路径信息包含”::”分隔符时启动该模式。如:rsync -av /databack root@172.16.78.192::www
6)列远程机的文件列表。这类似于rsync传输,不过只要在命令中省略掉本地机信息即可。如:rsync -v rsync://172.16.78.192/www

rsync参数的具体解释如下:

-v, –verbose 详细模式输出
-q, –quiet 精简输出模式
-c, –checksum 打开校验开关,强制对文件传输进行校验
-a, –archive 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD
-r, –recursive 对子目录以递归模式处理
-R, –relative 使用相对路径信息
-b, –backup 创建备份,也就是对于目的已经存在有同样的文件名时,将老的文件重新命名为~filename。可以使用–suffix选项来指定不同的备份文件前缀。
–backup-dir 将备份文件(如~filename)存放在在目录下。
-suffix=SUFFIX 定义备份文件前缀
-u, –update 仅仅进行更新,也就是跳过所有已经存在于DST,并且文件时间晚于要备份的文件。(不覆盖更新的文件)
-l, –links 保留软链结
-L, –copy-links 想对待常规文件一样处理软链结
–copy-unsafe-links 仅仅拷贝指向SRC路径目录树以外的链结
–safe-links 忽略指向SRC路径目录树以外的链结
-H, –hard-links 保留硬链结
-p, –perms 保持文件权限
-o, –owner 保持文件属主信息
-g, –group 保持文件属组信息
-D, –devices 保持设备文件信息
-t, –times 保持文件时间信息
-S, –sparse 对稀疏文件进行特殊处理以节省DST的空间
-n, –dry-run现实哪些文件将被传输
-W, –whole-file 拷贝文件,不进行增量检测
-x, –one-file-system 不要跨越文件系统边界
-B, –block-size=SIZE 检验算法使用的块尺寸,默认是700字节
-e, –rsh=COMMAND 指定使用rsh、ssh方式进行数据同步
–rsync-path=PATH 指定远程服务器上的rsync命令所在路径信息
-C, –cvs-exclude 使用和CVS一样的方法自动忽略文件,用来排除那些不希望传输的文件
–existing 仅仅更新那些已经存在于DST的文件,而不备份那些新创建的文件
–delete 删除那些DST中SRC没有的文件
–delete-excluded 同样删除接收端那些被该选项指定排除的文件
–delete-after 传输结束以后再删除
–ignore-errors 及时出现IO错误也进行删除
–max-delete=NUM 最多删除NUM个文件
–partial 保留那些因故没有完全传输的文件,以是加快随后的再次传输
–force 强制删除目录,即使不为空
–numeric-ids 不将数字的用户和组ID匹配为用户名和组名
–timeout=TIME IP超时时间,单位为秒
-I, –ignore-times 不跳过那些有同样的时间和长度的文件
–size-only 当决定是否要备份文件时,仅仅察看文件大小而不考虑文件时间
–modify-window=NUM 决定文件是否时间相同时使用的时间戳窗口,默认为0
-T –temp-dir=DIR 在DIR中创建临时文件
–compare-dest=DIR 同样比较DIR中的文件来决定是否需要备份
-P 等同于 –partial
–progress 显示备份过程
-z, –compress 对备份的文件在传输时进行压缩处理
–exclude=PATTERN 指定排除不需要传输的文件模式
–include=PATTERN 指定不排除而需要传输的文件模式
–exclude-from=FILE 排除FILE中指定模式的文件
–include-from=FILE 不排除FILE指定模式匹配的文件
–version 打印版本信息
–address 绑定到特定的地址
–config=FILE 指定其他的配置文件,不使用默认的rsyncd.conf文件
–port=PORT 指定其他的rsync服务端口
–blocking-io 对远程shell使用阻塞IO
-stats 给出某些文件的传输状态
–progress 在传输时现实传输过程
–log-format=formAT 指定日志文件格式
–password-file=FILE 从FILE中得到密码
–bwlimit=KBPS 限制I/O带宽,KBytes per second
-h, –help 显示帮助信息

PHP CURL 的使用技巧

curl只获取请求的请求头信息

$url = ‘https://www.baidu.com’;
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_HEADER, true); //返回头信息
curl_setopt($handle, CURLOPT_NOBODY, true); //不返回内容
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); //返回数据不直接输出
$header_content = curl_exec($handle); //执行并存储结果
curl_close($handle);
echo $header_content;

curl 请求内容写入文件

$url = ‘https://www.baidu.com’;
$handle = curl_init($url);
$tmp_file = tempnam(‘/tmp’,’uxf’);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
$file_res = fopen($tmp_file,’w’);
curl_setopt($handle, CURLOPT_FILE, $file_res);
curl_exec($handle);
fclose($file_res);
curl_close($handle);

 

curl: (35) SSL connect error的解决方法

先升级 nss(Mozilla Network Security Services 网络安全服务): yum update nss

再重启PHP:service php-fpm restart问题解决。

mysql 主从报错

mysql从机宕机bin日志报错解决办法

show slave status\G
提示错误:Relay log read failure: Could not parse relay log event entry
查看状态
Exec_Master_Log_Pos =
操作
mysql>stop slave;
mysql>change master to Master_Log_File=’mysql-bin.005121′, Master_Log_Pos=4;
mysql>start slave;
更新master的 当前要执行的日志位置,Master_Log_Pos 的值为 Exec_Master_Log_Pos 的值。

 

WordPress 使用SMTP

wordpress 发邮件默认使用系统的mail,mail发送的邮件经常被直接放垃圾箱或直接屏敝掉,使用SMTP是另一种简单的选择。

配置

在主题的function.php中加入


add_action('phpmailer_init','mail_init');
function mail_init(&$mail){
	$mail->isSMTP();
	$mail->Host = 'smtp.163.com';
	//$mail->SMTPDebug = 4;
	$mail->SMTPAuth = true;
	$mail->From = 'test@163.com';
	$mail->Username = 'test@163.com';
	$mail->Password = 'password';
}

 

php facst-cgi 502 bad gate way

当nginx + PHP 使用 unix socket 配置时

location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
nginx 必须要有 /tmp/php-cgi.sock 套接字文件有读写权限,不然会报 502 bad gateway 的错误。

一般php-fpm的用户与nginx为同一用户,这样可减少权限的问题。