Open mingyun opened 6 years ago
function urlsafe_base64_encode($data)
{
return strtr(base64_encode($data), ['+' => '-', '/' => '_', '=' => '']);
}
function urlsafe_base64_decode($data, $strict = false)
{
return base64_decode(strtr($data, '-_', '+/'), $strict);
}
use Illuminate\Queue\InteractsWithQueue; use InteractsWithQueue; if($this->attempts()>3){ $this->delete();检查这个工作已经被执行的次数 } Mac 上的文件系统 HFS+ 默认是大小写不敏感 文件名大小写变化,git 根本没有任何察觉 删除旧文件,提交代码。 添加新文件,提交代码。 git config core.ignorecase false $ git mv test.txt tmp.txt $ git mv tmp.txt Test.txt $ git commit -m "Renamed test.txt to Test.txt" https://www.lijinma.com/ 开发环境我们想测试的时候,可以把 Queue driver 设置成为 sync,这样队列就变成了同步执行,方便调试队列里面的任务
127.0.0.1:6379>monitor LRANGE "queues:default" 0 -1 获取 List 里面的所有数据。 ZRANGE ”queues:default:reserved“ 0 -1 获取 zset 里面的所有数据。 ZRANGEBYSCORE queues:default:reserved -inf +inf 通过时间来排序获取所有数据 使用 json_encode([]) 得到的结果是
那如何返回一个 {} (json) json_encode(new stdClass) 我觉得写一个接口应该考虑如下的内容:
确定 url:是否符合 Restful,是否要符合公司确定的规范? 确认操作人的权限 确定要操作的资源的权限 验证传入的参数:不要相信外面传进来的任何数据 操作失败的提示 操作成功的提示 写文档:如何按规矩写好文档是一件值得花时间和精力梳理的事情 如何测试接口,用什么数据测试 求10100001中1的数量是奇数还是偶数; 答案:1 ^ 0 ^ 1 ^ 0 ^ 0 ^ 0 ^ 0 ^ 1 = 1,结果为1就是奇数个1,结果为0就是偶数个1; 你肯定会想到判断a - b == 0,但是如果判断a ^ b == 0效率将会更高
RedisClient::getInstance()->lPush($key,json_encode($data));
RedisClient::getInstance()->lTrim($key,0,10);//截取前10条
/**
* 队列处理 根据房间号 self::$roomMsgSeconds 秒之内处理 self::$roomMsgMaxNum 条 如果超过 直接丢弃数据 不往nginx push stream 推了
* @return bool
*/
public function sendAction(){
set_time_limit(0);
$startTime = time();
$duration = 300;
while (time() - $startTime < $duration){
$this->_currentLimiting();
usleep(100000);
}
}
/**
* 房间限流处理 60秒限制 100
* @param $roomKey
* @return bool
*/
private function _currentLimiting($roomKey){
$maxNum = RedisClient::getInstance()->incr($roomKey);
if($maxNum <=1){
RedisClient::getInstance()->expire($roomKey,60);
}else if($maxNum > 100){
//如果值大于20000 记录日志处理
if($maxNum >= 20000 ){
Common::writeLog('timeout key '.$roomKey.' num '.$maxNum,'error','redisTimeoutKey');
}
return false;
}else{
return true;
}
return true;
}
$str = "昵称\t添加时间\t消息内容\tTo\n";
$str = iconv('utf-8','GBK//IGNORE',$str);
foreach($ret as $val){
$userName = !empty($val['user_name']) ? iconv('utf-8','GBK//IGNORE',$val['user_name']) : '-';
$addTime = !empty($val['created_at'])? iconv('utf-8','GBK//IGNORE',$val['created_at']): '-';
$text = !empty($val['content']) ? iconv('utf-8','GBK//IGNORE',$val['content']) : '-';
$to = !empty($val['nick_name']) ? iconv('utf-8','GBK//IGNORE',$val['nick_name']) : '-';
$text = str_replace(array("\r\n", "\r", "\n"), "", $text);
$str .= $userName."\t".$addTime."\t".$text."\t".$to."\n";
}
$fileName = date('YmdHis').'_'.$room.'.xls';
$this->_exportData($fileName,$str);
}
private function _exportData($fileName,$content){
header("Content-type: text/html; charset=utf-8");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/vnd.ms-execl");
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".$fileName);
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");
echo $content;exit;
}
function get_ip_address(){
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key){
if (array_key_exists($key, $_SERVER) === true){
foreach (explode(',', $_SERVER[$key]) as $ip){
$ip = trim($ip); // just to be safe
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false){
return $ip;
}
}
}
}
}location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
著作权归作者所有。
商业转载请联系作者获得授权,非商业转载请注明出处。
作者:mokeyjay
链接:https://www.mokeyjay.com/archives/1166
来源:超能小紫
// 过滤掉emoji表情
function filterEmoji($str)
{
$str = preg_replace_callback(
'/./u',
function (array $match) {
return strlen($match[0]) >= 4 ? '' : $match[0];
},
$str);
return $str;
}
https://www.cnblogs.com/weafer/archive/2011/09/21/2184059.html lpop命令的block版本。即当timeout为0时,若遇到名称为key i的list不存在或该list为空,则命令结束。
通常一些比较耗时的任务如发邮件,短信,不需要马上获取发送状态,可以使用队列来处理,之前在 sf 公众号看了一篇关于 redis 延时队列的文章 https://mp.weixin.qq.com/s/Dkz85tZgTs7aPYSJoq4XwA 分享给大家
简单的队列处理
入队列
消费队列
laravel 延时队列
一分钟限制请求 100 次