0.后台 循环N*10000次操作的简单处理

后台需要循环做N*10000次级别的工作时候,比如,发送邮件,推送通知。可以先把所有数据导入数据表(数据库操作所需的时间1~2秒),然后前台循环发送请求,每个请求,可以执行一次或多次操作,比如一次请求发10封邮件,10个通知等(这些控制,根据需求来定),这样,就可以把任务做成一种类似进度条的效果,并且可以直接展示给用户看,提高用户体验。

1.empty(trim($ch_url) :报错

手册:

在 PHP 5.5 之前,empty() 仅支持变量;任何其他东西将会导致一个解析错误。换言之,下列代码不会生效: empty(trim($name))。 作为替代,应该使用trim($name) == false.

2.手机信息提示框(你懂的,复制,粘贴)

<script type='text/javascript' src='resource/js/lib/jquery-1.11.1.min.js'></script>
<style type='text/css'>
#poptip { position: fixed; top:40%;left:50%;width:160px;margin-left:-80px;height: 27px;background:#000; opacity: 0.7;filter:alpha(opacity=0.7); color:#fff;z-index: 999; border-radius:5px;-webkit-border-radius:5px;-moz-border-radius:5px;}
#poptip_content { position: fixed; top:40%;left:50%;width:160px;margin-left:-80px; height: 27px; color:#fff;text-align:center;font-size:14px;z-index: 999999}
</style>
<script language='javascript'>
function tip(msg,autoClose){
var div = $("#poptip");
var content =$("#poptip_content");
if(div.length<=0){
div = $("<div id='poptip'></div>").appendTo(document.body);
content =$("<div id='poptip_content'>" + msg + "</div>").appendTo(document.body);
}else{
content.html(msg);
content.show(); div.show();
}
if(autoClose) {
setTimeout(function(){
content.fadeOut(500);
div.fadeOut(500);
},1000);
}
}
function tip_close(){
$("#poptip").fadeOut(500);
$("#poptip_content").fadeOut(500);
}
</script>

达到以下效果:

  

3.使用PHP QR Code生成二维码

phpQrCode 官网:http://phpqrcode.sourceforge.net/

使用:引入phpqrcode.php

封装的代码:

/**
* 建立文件夹
*
* @param string $aimUrl
* @return viod
*/
function createDir($aimUrl) {
$aimUrl = str_replace('', '/', $aimUrl);
$aimDir = '';
$arr = explode('/', $aimUrl);
$result = true;
foreach ($arr as $str) {
$aimDir .= $str . '/';
if (!file_exists($aimDir)) {
$result = mkdir($aimDir,0777,true);
}
}
return $result;
} /* --------------------------------------------------------------------
* 创建二维码
* @param content 二维码内容
* @param logoPath 图片文件,或者url
* @param fileName 生成的文件名
* @param errorCorrectionLevel 容错级别 :L、M、Q、H
*/
function create_qrcode($content, $logoPath = FALSE, $fileName = FALSE, $errorCorrectionLevel = 'M'){ $errorCorrectionLevels = array('L', 'M', 'Q', 'H');
$errorCorrectionLevel = in_array($errorCorrectionLevel, $errorCorrectionLevels) ? $errorCorrectionLevel : "M"; $matrixPointSize = 6; // 点的大小:1到10 if($logoPath == FALSE || empty($logoPath)){ //生成二维码图片
QRcode::png($content, false, $errorCorrectionLevel, $matrixPointSize, 2);
}
else{ $path = ATTACHMENT_ROOT . 'temp/qrcode/' . date('Ymd', time());
$fileName = $path . '/' . $fileName;
createDir($path); $QR = $fileName; QRcode::png($content, $QR, $errorCorrectionLevel, $matrixPointSize, 2); $QR = imagecreatefromstring(file_get_contents($QR)); $logo = imagecreatefromstring(file_get_contents($logoPath)); $QR_width = imagesx($QR); // 二维码图片宽度 $QR_height = imagesy($QR); //二维码图片高度 $logo_width = imagesx($logo); //logo图片宽度 $logo_height = imagesy($logo); //logo图片高度 $logo_qr_width = $QR_width / 5; $scale = $logo_width/$logo_qr_width; $logo_qr_height = $logo_height/$scale; $from_width = ($QR_width - $logo_qr_width) / 2; //重 新组合图片并调整大小
imagecopyresampled(
$QR,
$logo,
$from_width,
$from_width,
0, 0,
$logo_qr_width,
$logo_qr_height,
$logo_width,
$logo_height);
} // 输出图片
Header("Content-type:image/png");
// header("Content-type:image/png");
// header("Content-Disposition:attachment; filename=meimei.png");
ImagePng($QR);
}

4.导出 Excel

关键性代码是:使用 header 即可导出数据

Tip : 这种方式采用 ajax 就不合适了,最好就是一个链接。

header("Content-type:text/csv");
header("Content-Disposition:attachment; filename=" . date('Y-m-d', time()) . "-代金券核销数据.csv");

剩下的工作,就是拼接字符串了。

例子:

<?php
$html = "\xEF\xBB\xBF";
$filter = array(
'uid' => 'ID',
'realname' => '姓名',
'carno' => '车牌号码',
'title' => '标题',
'discount' => '面额',
/* ... 等等 */
);
foreach ($filter as $title) {
$html .= $title . "\t,";
}
$html .= "\n";
foreach ($exports as $k => $v) { // exports 为所有需要导出的数据 foreach ($filter as $key => $title) { if ($key == 'uid') {
$html .= $v['uid'] . "\t, ";
}
elseif ($key == 'realname') {
$html .= $v['realname']. "\t, ";
}
elseif ($key == 'carno') {
$html .= $v['carno']. "\t, ";
}
elseif ($key == 'title') {
$html .= $v['title']. "\t, ";
}
elseif ($key == 'discount') {
$html .= $v['discount']. "\t, ";
}
} $html .= "\n";
} header("Content-type:text/csv");
header("Content-Disposition:attachment; filename=" . date('Y-m-d', time()) . "-代金券核销数据.csv");
echo $html;
exit();

  

php : 开发记录(2017-03-10)的更多相关文章

  1. 个人知识管理系统Version1.0开发记录(03)

    demo  设 计 一个知识点demo,在数据库和用户界面的互动事件.分三个层次,数据存储,数据方法工具,数据呈现界面.这一次先完成数据存储,按以下逻辑实现.工具:eclipse,oracle数据库, ...

  2. CozyRSS开发记录17-Html2Xaml

    CozyRSS开发记录17-Html2Xaml 1.RssContentView还需要优化 上回做了RssContentView的显示,但是对于rss返回的描述(摘要),连换行的没有,更别说里面还有h ...

  3. Python全栈开发记录_第一篇(循环练习及杂碎的知识点)

    Python全栈开发记录只为记录全栈开发学习过程中一些难和重要的知识点,还有问题及课后题目,以供自己和他人共同查看.(该篇代码行数大约:300行) 知识点1:优先级:not>and 短路原则:a ...

  4. .Net Core ORM选择之路,哪个才适合你 通用查询类封装之Mongodb篇 Snowflake(雪花算法)的JavaScript实现 【开发记录】如何在B/S项目中使用中国天气的实时天气功能 【开发记录】微信小游戏开发入门——俄罗斯方块

    .Net Core ORM选择之路,哪个才适合你   因为老板的一句话公司项目需要迁移到.Net Core ,但是以前同事用的ORM不支持.Net Core 开发过程也遇到了各种坑,插入条数多了也特别 ...

  5. easyUI datebox 日期空间斜杠格式化。例如将日期空间中显示2017-03-13,改为2017/03/13

    easyUI datebox 日期空间斜杠格式化 将日期空间中显示2017-03-13,改为2017/03/13 //日期控件斜杠格式化 function formatDate(date){ if( ...

  6. Linux GPIO键盘驱动开发记录_OMAPL138

    Linux GPIO键盘驱动开发记录_OMAPL138 Linux基本配置完毕了,这几天开始着手Linux驱动的开发,从一个最简单的键盘驱动开始,逐步的了解开发驱动的过程有哪些.看了一下Linux3. ...

  7. JFinal使用笔记3-注册和登录功能开发记录

    首页 开源项目 问答 代码 博客 翻译 资讯 移动开发 招聘 城市圈 当前访客身份:游客 [ 登录 | 加入开源中国 ]   当前访客身份: 游客 [ 登录 | 加入开源中国 ] 软件   土龙 关注 ...

  8. Anytime项目开发记录0

    Anytime,中文名:我很忙. 开发者:孤独的猫咪神. 这个项目会持续更新,直到我决定不再维护这个APP. 2014年3月10日:近日有事,暂时断更.希望可以会尽快完事. 2014年3月27日:很抱 ...

  9. Android开发 SeekBar开发记录

    前言 开发记录博客不是讲解使用博客,更多的是各种功能与点子的记录 基本使用 <SeekBar android:layout_width="match_parent" andr ...

  10. CozyRSS开发记录22-界面退化

    CozyRSS开发记录22-界面退化 1.问题1-HtmlTextBlock 找的这个HtmlTextBlock有很严重的bug,有时候显示不完全,有时候直接就崩了.然后看了下代码,完全是学生仔水平写 ...

随机推荐

  1. BZOJ 4260 Codechef REBXOR (区间异或和最值) (01字典树+DP)

    <题目链接> 题目大意:给定一个序列,现在求出两段不相交的区间异或和的最大值. 解题分析: 区间异或问题首先想到01字典树.利用前缀.后缀建树,并且利用异或的性质,相同的两个数异或变成0, ...

  2. Codeforces 1036E Covered Points (线段覆盖的整点数)【计算几何】

    <题目链接> <转载于 >>>  > 题目大意: 在二维平面上给出n条不共线的线段(线段端点是整数),问这些线段总共覆盖到了多少个整数点. 解题分析: 用GC ...

  3. python简单名片管理系统

  4. linux 学习笔记 TAR包管理

    >显示gong.tar 文件内容 #tar tf gong.tar ./epuinfo.txt ./smart/ ./smart/smartsuite-2.1-2.i386.rpm ./smar ...

  5. [OC] Block的使用

    由ControllerA跳转到controllerB,在controllerB中选择一个参数的值,并将它传回给controllerA. 首先,在controllerB的.h文件中写入: @interf ...

  6. JS 对象引用问题

    var a = {n:1}; var b = a; a = {n:2}; a.x = a ;console.log(a.x);console.log(b.x); var a = {n:1}; var ...

  7. Python datetime与timestamp之间的转换

    # !!!! Python 2 datetime.datetime 对象没有timestamp方法! 在用Python处理datetime和timestamp的转换时发现在时区方面,Python的处理 ...

  8. Linux之Redis安装

    一.下载解压 1 2 3 4 ## 下载Redis wget http://download.redis.io/releases/redis-2.8.17.tar.gz ## 解压 tar zxvf ...

  9. js数组根据指定字段(true or false)排序

    const obj = [ {name:'1',bind:true}, {name:'2',bind:false}, {name:'3',bind:true}, {name:'4',bind:fals ...

  10. fetch添加超时时间

    fetch添加超时时间 其实为fetch添加超时时间很简单,需要用到Promise.race()方法. Promise.race() 方法将多个Promise包装成一个新的Promise实例. var ...