杜郎俊赏 - dujun.io

建站之 redis 纯内存运行

mysql 做永久存储,redis 做缓存。所以将 redis 设置为纯内存运行,减少开销。 编辑 /etc/redis/redis.conf,修改下列几项 #注释掉 save 项 #save 900 1 #save 300 10 #save 60 10000 #设置最多 1G 内存 maxmemory 1GB maxmemory-policy volatile-lru appendfsync no

2017-05-19

建站之视频处理

借助 ffmpeg 扩展处理视频。包括自动旋转、截图、转换格式等。 ubuntu 下安装扩展 sudo apt-get install ffmpeg 获取视频尺寸、旋转角度 /** * /usr/bin/ffprobe video.mp4 -show_streams -print_format json */ public static function info($video) { $raw = shell_exec(sprintf('%s %s -show_streams -print_format json', self::ffprobe(), $video)); if (empty($raw) || !($raw = json_decode($raw, true)) || empty($raw['streams'])) { return fals...

2017-05-18

建站之友好时间显示

public function format($time) { if (invalid_integer($time)) { return ''; } $now = time(); $today = strtotime(date('Y-m-d', $now)); $tmp = $now - $time; if (60 > $tmp) { return '刚刚'; } elseif (3600 > $tmp) { return floor($tmp / 60) . ' 分钟前'; } elseif (86400 > $tmp) { return floor($tmp / 3600) . ' 小时前'; } $time = strtotime(date...

2017-05-18

建站之阿里云邮件推送

评论被回复时,如果评论者填了邮箱,则向其发送通知邮件。使用阿里云的邮件推送。每日免费额度 200 封。 /** * 发送阿里云邮件 */ class Util_Mail { private static $url, $accessId, $accessSecret, $account, $name; public static function send($title, $content, $receiver = null) { if (empty($title) || empty($content)) { return false; } self::init(); if (is_null($receiver)) { $receiver = Commo...

2017-05-18

建站之图片缩略图

难点在于,gif 图片直接截缩略图可能有巨大噪音,所以改为截取第一帧。 //生成缩略图 public static function createThumb($imagePath) { try { if (!($imagePath = File::exist($imagePath))) { return false; } if (is_mobile()) { //移动端生成更小的图 $path = $imagePath . '_s.jpg'; $maxWidth = 147; } else { $path = $imagePath . '_m.jpg'; $maxWidth =...

2017-05-18

建站之图片大小调整

借助 imagemagick 扩展调整图片大小。 $maxSize = 2097152; //图片限制 2M $maxWidth = 1024; $maxHeight = 768; try { do { $imagick = new Imagick($imagePath); if ($maxSize >= $imagick->getImageLength()) { break; } if ($maxWidth < $imagick->getImageWidth()) { $imagick->scaleImage($maxWidth, 0); } elseif ($maxHeight < $imagick->getImageHeight()) {...

2017-05-18

634封面

2017-05-18

建站之图片旋转

手机拍摄的照片存在旋转的问题,借助 imagemagick 扩展解决。 安装扩展: sudo apt-get install imagemagick sudo apt-get install php-imagick 旋转图片: try { $imagick = new Imagick($imagePath); if ($orientation = $imagick->getImageOrientation()) { switch ($orientation) { case 8: //逆时针90° $degrees = -90; break; case 3: //180° $degrees = -180...

2017-05-18

建站之 gravatar 缓存

为解决 gravatar 头像访问慢和被墙的问题,可以做本地图片备份。 $url = 'https://secure.gravatar.com/avatar/' . md5($mail) . '?s=36&r=G&d=404'; $header = get_headers($url); if (empty($header) || false === strpos($header[0], '200')) { //此邮箱不存在 gravatar 头像 } else { //抓取头像图片 $image = file_get_contents($url); }

2017-05-18

建站之 yaf 框架

用 yaf 框架重新开发了整站。 ubuntu 下安装命令: sudo apt-get install php7.0-dev sudo pecl install yaf 修改php.ini,追加内容 [yaf] extension=yaf.so yaf.use_namespace=1 yaf.environ=develop

2017-05-17

分页: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183