CentOS7 GIF 压缩 Gifsicle 安装

Gifsicle 官网

cd ~
wget https://www.lcdf.org/gifsicle/gifsicle-1.91.tar.gz 
tar -zxvf gifsicle-1.91.tar.gz
cd gifsicle-1.91/
make install


gifsicle -O3 path.gif -o newpath.gif
[root@instance-jewlel2q tmp]# gifsicle --sinfo x.gif
* x.gif 98 images
  logical screen 800x450
  global color table [256]
  background 0
  loop forever
  + image #0 800x450
    compressed size 133044
    comment Edited with ezgif.com online GIF maker
    disposal asis delay 0.10s
  + image #1 800x450
    compressed size 133243
    local color table [256]
    disposal asis delay 0.10s
  + image #2 800x450
    compressed size 134192
    local color table [256]
    disposal asis delay 0.10s
  + image #3 800x450
    compressed size 130221
    local color table [256]
    disposal asis delay 0.10s
[root@instance-jewlel2q tmp]# gifsicle -O3 x.gif -o x1.gif --resize-fit 400
gifsicle: invalid dimensions ‘400’ (want WxH)
gifsicle: warning: too many colors, using local colormaps
  (You may want to try ‘--colors 256’.)
[root@instance-jewlel2q tmp]# gifsicle -h
'Gifsicle' manipulates GIF images. Its most common uses include combining
single images into animations, adding transparency, optimizing animations for
space, and printing information about GIFs.

Usage: gifsicle [OPTION | FILE | FRAME]...

Mode options: at most one, before any filenames.
  -m, --merge                   Merge mode: combine inputs, write stdout.
  -b, --batch                   Batch mode: modify inputs, write back to
                                same filenames.
  -e, --explode                 Explode mode: write N files for each input,
                                one per frame, to 'input.frame-number'.
  -E, --explode-by-name         Explode mode, but write 'input.name'.

General options: Also --no-OPTION for info and verbose.
  -I, --info                    Print info about input GIFs. Two -I's means
                                normal output is not suppressed.
      --color-info, --cinfo     --info plus colormap details.
      --extension-info, --xinfo --info plus extension details.
      --size-info, --sinfo      --info plus compression information.
  -V, --verbose                 Prints progress information.
  -h, --help                    Print this message and exit.
      --version                 Print version number and exit.
  -o, --output FILE             Write output to FILE.
  -w, --no-warnings             Don't report warnings.
      --no-ignore-errors        Quit on very erroneous input GIFs.
      --conserve-memory         Conserve memory at the expense of speed.
      --multifile               Support concatenated GIF files.

Frame selections:               #num, #num1-num2, #num1-, #name

Frame change options:
  --delete FRAMES               Delete FRAMES from input.
  --insert-before FRAME GIFS    Insert GIFS before FRAMES in input.
  --append GIFS                 Append GIFS to input.
  --replace FRAMES GIFS         Replace FRAMES with GIFS in input.
  --done                        Done with frame changes.

Image options: Also --no-OPTION and --same-OPTION.
  -B, --background COL          Make COL the background color.
      --crop X,Y+WxH, --crop X,Y-X2,Y2
                                Crop the image.
      --crop-transparency       Crop transparent borders off the image.
      --flip-horizontal, --flip-vertical
                                Flip the image.
  -i, --interlace               Turn on interlacing.
  -S, --logical-screen WxH      Set logical screen to WxH.
  -p, --position X,Y            Set frame position to (X,Y).
      --rotate-90, --rotate-180, --rotate-270, --no-rotate
                                Rotate the image.
  -t, --transparent COL         Make COL transparent.

Extension options:
      --app-extension N D       Add an app extension named N with data D.
  -c, --comment TEXT            Add a comment before the next frame.
      --extension N D           Add an extension number N with data D.
  -n, --name TEXT               Set next frame's name.
      --no-comments, --no-names, --no-extensions
                                Remove comments (names, extensions) from input.
Animation options: Also --no-OPTION and --same-OPTION.
  -d, --delay TIME              Set frame delay to TIME (in 1/100sec).
  -D, --disposal METHOD         Set frame disposal to METHOD.
  -l, --loopcount[=N]           Set loop extension to N (default forever).
  -O, --optimize[=LEVEL]        Optimize output GIFs.
  -U, --unoptimize              Unoptimize input GIFs.
  -j, --threads[=THREADS]       Use multiple threads to improve speed.

Whole-GIF options: Also --no-OPTION.
      --careful                 Write larger GIFs that avoid bugs in other
      --change-color COL1 COL2  Change COL1 to COL2 throughout.
  -k, --colors N                Reduce the number of colors to N.
      --color-method METHOD     Set method for choosing reduced colors.
  -f, --dither                  Dither image after changing colormap.
      --gamma G                 Set gamma for color reduction [2.2].
      --resize WxH              Resize the output GIF to WxH.
      --resize-width W          Resize to width W and proportional height.
      --resize-height H         Resize to height H and proportional width.
      --resize-fit WxH          Resize if necessary to fit within WxH.
      --scale XFACTOR[xYFACTOR] Scale the output GIF by XFACTORxYFACTOR.
      --resize-method METHOD    Set resizing method.
      --resize-colors N         Resize can add new colors up to N.
      --transform-colormap CMD  Transform each output colormap by shell CMD.
      --use-colormap CMAP       Set output GIF's colormap to CMAP, which can
                                be 'web', 'gray', 'bw', or a GIF file.

Report bugs to <ekohler@gmail.com>.
Too much information? Try 'gifsicle --help | more'.

监测 MySQL 服务 挂掉自动重启

最近 MySQL 服务总是挂掉

cd ~
vim /mysqllisten.sh
pgrep -x mysqld &> /dev/null
if [ $? -ne 0 ]
echo "MySQL stoped at time: `date` ">> /home/wwwlogs/mysql_messages
/etc/init.d/mysql restart
sleep 15s
MYSQLPORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $4}'`
    if [ "$MYSQLPORT" == "3306" ]
            echo "MySQL restart successful at time: `date` ">> /home/wwwlogs/mysql_messages   
            echo "MySQL restart failed at time: `date` ">> /home/wwwlogs/mysql_messages 
            mail -s "wann! yourwebsitedomain's mysql restart failed" 这里写你的邮箱地址
echo "MySQL server is running"
chmod +x ./mysqllisten.sh


crontab -e

*/10 * * * * /bin/bash /root/mysqllisten.sh

service crond restart



Swoole 编译报错 fatal error: hiredis/hiredis.h: No such file or directory

Swoole 当使用参数 –enable-async-redis 时编译报错

/tmp/pear/temp/swoole/swoole_redis.c:20:29: fatal error: hiredis/hiredis.h: No such file or directory

启用 Swoole 的 async-redis 扩展需要安装 hiredis,hiredis 需要 redis

安装 Redis

cd ~
wget http://download.redis.io/releases/redis-5.0.0.tar.gz
tar xzf redis-5.0.0.tar.gz
cd redis-5.0.0

安装 hiredis

cd ~
wget https://github.com/redis/hiredis/archive/v0.13.3.zip
unzip v0.13.3.zip
cd hiredis-0.13.3
make -j
sudo make install
sudo ldconfig

Swoole 编译错误 Enable http2 support, require nghttp2 library

安装 nghttp2

In file included from /tmp/pear/temp/swoole/swoole.c:16:0:
/tmp/pear/temp/swoole/php_swoole.h:142:2: error: #error "Enable http2 support, require nghttp2 library."
 #error "Enable http2 support, require nghttp2 library."

swoole 的 http2 模块依赖  nghttp2库,安装即可

wget https://github.com/nghttp2/nghttp2/releases/download/v1.30.0/nghttp2-1.30.0.tar.bz2 
tar -jxvf nghttp2-1.30.0.tar.bz2 
cd nghttp2-1.30.0 
make install

安装 PostgreSQL


configure: error: Cannot find libpq-fe.h. Please confirm the libpq or specify correct PostgreSQL(libpq) installation path
ERROR: `/tmp/pear/temp/swoole/configure --with-php-config=/usr/local/php/bin/php-config --enable-sockets=yes --enable-openssl=yes --enable-http2=yes --enable-mysqlnd=yes --enable-coroutine-postgresql=yes --enable-debug-log=yes' failed


yum -y install postgresql-devel

PHP 使用 exec 搭配 MozJPEG 的一些心得

环境 CentOS 7 PHP 7.2.6

查看 php 所在用户与用户组

为 www:www

将 www 用户添加至 root 权限

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL

允许 root 用户执行任何命令在任何位置。NOPASSWD  后为执行哪些命令不用输入密码

reboot 重启系统

PHP 测试命令

echo exec('php -v',$a1,$b1);

echo exec('sudo /opt/mozjpeg/bin/cjpeg -version',$a2,$b2);

echo exec('sudo /opt/mozjpeg/bin/cjpeg -quality 60 -debug /home/wwwroot/hi.unetu.net/public/tmp/uploads/1.jpeg > /home/wwwroot/hi.unetu.net/public/uploads/1.jpeg',$a3,$b3);



exec 中第三个参数为 0 表示执行成功,其他值如 1 表示失败,上述代码表示执行成功但第二和第三个命令没有返回值也没有输出值

其中第三条 mozjpeg/cjpeg 的压缩图片执行成功

如果想要返回值,查找了一下可以使用管道,在命令添加 2>&1,尝试如下





第三条 MozJPEG 如果原图片损坏,则第三条返回 int(1),表示执行失败