我所经历的大文件数据导出(后台执行,自动生成)
一、前言
记录一下以前做的后台excel格式导出统计信息的功能,也是最近同事问到了相关东西,一时之间竟忘了具体的细节,因此记录一下;
大家知道,excel导出数据的功能,后台几乎是必须功能,一般都是点击后,生成文件然后自动下载,
如果是数据量小的话,一下子便可请求完成,从而下载到本地;
但是,如果数据量特别大的时候,页面就必须一直在等待,直到写入excel成功,
这样便影响了后台使用者无法操作其他页面,为此,对excel导出做了以下功能优化:
- excel导出分成两部分内容:生成excel文件和下载excel文件
- excel的文件生成在程序后台执行,前端不必等待,可进行其他后台操作
- 增加下载文件页面,显示excel文件生成的进度,完成后,方可下载生成的excel文件
- 文件生成后,点击下载方可下载相应的文件
二、生成excel文件
生成excel文件的方法有很多,暂不一一记录,只是记录本次的方法;
这里用到了table的html格式,以及相应的excel的声明
(隐约记得其他的方法用office07打开的时候好像是乱码,后面尝试用csv格式文件,可还是乱码,所以用了table的形式)
文件的开头:


<span style="font-family: 'Microsoft YaHei';"><span style="color: #008080;"> 1</span> <span style="color: #800080;">$struserdata</span> = Eof</span><span style="color: #008080;"> 2</span> 3 xmlns:x="urn:schemas-microsoft-com:office:excel"<span style="color: #008080;"> 4</span> xmlns="http://www.w3.org/TR/REC-html40"><span style="color: #008080;"> 5</span> <span style="color: #008080;"> 6</span> span style="color: #0000ff;">PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><span style="color: #008080;"> 7</span> <span style="color: #008080;"> 8</span> <span style="color: #008080;"> 9</span> <meta http-equiv="Content-type" content="text/html;charset=utf-8"><span style="color: #008080;">10</span> <style id="Classeur1_16681_Styles"><span style="color: #008080;">11 </style><span style="color: #008080;">12</span> <span style="color: #008080;">13</span> <span style="color: #008080;">14</span> <div id="Classeur1_16681" align="center" x:publishsource="Excel"> <span style="color: #008080;">15</span> <span style="color: #008080;">16</span> <table x:str border="1" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse"> <span style="color: #008080;">17</span> Eof;<span class="cnblogs_code_collapse" style="font-family: 'Microsoft YaHei';">View Code</span><p><span style="font-family: 'Microsoft YaHei';"> 文件的结尾:</span></p> <div class="cnblogs_code" onclick="cnblogs_code_show('6e7814c6-7ec0-4037-94c2-b0b68682b66d')"> <span style="font-family: 'Microsoft YaHei';"><img class="code_img_closed lazy" src="/static/imghwm/default1.png" data-src="/img/2015/08/11/12404618.gif" id="code_img_closed_6e7814c6-7ec0-4037-94c2-b0b68682b66d" alt=""><img class="code_img_opened lazy" src="/static/imghwm/default1.png" data-src="/img/2015/08/11/12404619.gif" id="code_img_opened_6e7814c6-7ec0-4037-94c2-b0b68682b66d" style="max-width:90%" onclick="cnblogs_code_hide('6e7814c6-7ec0-4037-94c2-b0b68682b66d',event)" alt=""></span><div id="cnblogs_code_open_6e7814c6-7ec0-4037-94c2-b0b68682b66d" class="cnblogs_code_hide"><pre class="brush:php;toolbar:false"><span style="font-family: 'Microsoft YaHei';"><span style="color: #008080;">1</span> <span style="color: #800080;">$struserdata</span> = Eof</span><span style="color: #008080;">2</span>
当然,文件中间就是一些tr td 标签了。
三、让程序在后台执行
场景:
用户点击 生成excel后,跳转到下载页面,程序在后台执行,用户可不必等待生成完成,可执行其他操作;
下载页面可看到文件生成的进度以及是否可下载状态
思路:
点击 生成excel,显示下载页面 ---> show_download方法
生成excel ---> create_excel 方法
show_download方法中调用 create_excel方法,而show_download 方法中,自己用了一下命令行执行程序的方式,
利用php命令行的方式,把参数传递给 create_excel方法
<span style="font-family: 'Microsoft YaHei';"><span style="color: #008080;">1</span> <span style="color: #008000;">//</span><span style="color: #008000;"> $cmd = "/usr/bin/php /home/xxx/xxx.php " . $strjoin . " >/dev/null & ";</span><span style="color: #008080;">2</span> <span style="color: #008000;"> // $a=exec($cmd, $out, $returndata);</span><span style="color: #008080;">3</span> <span style="color: #008080;">4</span> <span style="color: #008080;">5</span> <span style="color: #800080;">$command</span> = "/usr/bin/php ".STATISTIC_EXPORT_SCRIPT_DIR."xxx.php " . "'" .<span style="color: #800080;">$strjoin</span> ."'". " " . <span style="color: #800080;">$uid</span> . " ". <span style="color: #800080;">$action</span> ." & "<span style="color: #000000;">;</span><span style="color: #008080;">6</span> <span style="color: #800080;">$process</span> = <span style="color: #008080;">proc_open</span>(<span style="color: #800080;">$command</span>, <span style="color: #0000ff;">array</span>(),<span style="color: #800080;">$pipes</span><span style="color: #000000;">); </span><span style="color: #008080;">7</span> <span style="color: #800080;">$var</span> = <span style="color: #008080;">proc_get_status</span>(<span style="color: #800080;">$process</span><span style="color: #000000;">); </span><span style="color: #008080;">8</span> <span style="color: #008080;">proc_close</span>(<span style="color: #800080;">$process</span><span style="color: #000000;">);</span><span style="color: #008080;">9</span> <span style="color: #800080;">$pid</span> = <span style="color: #008080;">intval</span>(<span style="color: #800080;">$var</span>['pid'])+1;</span>
而在create_excel方法中:
需填写以下代码:
<span style="font-family: 'Microsoft YaHei';"><span style="color: #008080;">1</span> <span style="color: #008080;">set_time_limit</span>(0); <span style="color: #008000;">//</span><span style="color: #008000;">取消脚本运行时间的超时上限</span><span style="color: #008080;">2</span> <span style="color: #008080;">3</span> <span style="color: #008080;">ignore_user_abort</span>(<span style="color: #0000ff;">TRUE</span>); <span style="color: #008000;">//</span><span style="color: #008000;">后台运行,不受用户关闭浏览器的影响</span></span>
调用相关的api得到数据:
<span style="font-family: 'Microsoft YaHei';"><span style="color: #008080;">1</span> <span style="color: #800080;">$statistic</span> = <span style="color: #008080;">call_user_func</span>(<span style="color: #0000ff;">array</span>('shellscript','get_result'),<span style="color: #800080;">$url</span>,<span style="color: #800080;">$params</span><span style="color: #000000;">);</span><span style="color: #008080;">2</span> <span style="color: #0000ff;">if</span>(!<span style="color: #008080;">is_object</span>(<span style="color: #800080;">$statistic</span>) || !<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$statistic</span>->data-><span style="color: #000000;">items)){</span><span style="color: #008080;">3</span> <span style="color: #008080;">usleep</span>(400000);<span style="color: #008000;">//</span><span style="color: #008000;">停止400毫秒</span><span style="color: #008080;">4</span> <span style="color: #800080;">$statistic</span> = <span style="color: #008080;">call_user_func</span>(<span style="color: #0000ff;">array</span>('shellscript','get_result'),<span style="color: #800080;">$url</span>,<span style="color: #800080;">$params</span><span style="color: #000000;">);</span><span style="color: #008080;">5</span> }</span>
四、显示文件生成进度
但是怎么显示相应的文件生成进度呢,怎么知道文件到底生成好了没有呢?
这里,我用到的方法是,在写入数据文件的时候data.xsl,每个数据文件都生成一个对应的文件进度文件,暂且称为flag_data.xsl;
思路:
- 第一次请求api的时候,根据返回的total总数,以及pagesize,确定要请求的次数count;
- 这样便可知道要请求api的次数(分页请求api),在写入数据文件的同时,同时写入进度文件flag_data.xsl;
数据格式大约是(以逗号分割)
1,5
2,5
...- 然后显示文件进度的时候,读取进度文件,这样变可知道数据文件大体的进度
- 前端js处理时,几秒读取一次相应的方法(如果都100%进度,可停止请求方法),从而实现动态查看文件的生成进度
查看文件的进度方法:


<span style="font-family: 'Microsoft YaHei';"><span style="color: #008080;"> 1</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> execscript_process(){</span><span style="color: #008080;"> 2</span> <span style="color: #800080;">$this</span>->load->library('smarty'<span style="color: #000000;">);</span><span style="color: #008080;"> 3</span> <span style="color: #800080;">$file_arr_str</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();</span><span style="color: #008080;"> 4</span> <span style="color: #800080;">$file_arr_process</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();</span><span style="color: #008080;"> 5</span> <span style="color: #800080;">$file_arr_name</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();</span><span style="color: #008080;"> 6</span> <span style="color: #800080;">$file_arr</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();</span><span style="color: #008080;"> 7</span> <span style="color: #800080;">$refresh_flag</span> = 'yes'<span style="color: #000000;">;</span><span style="color: #008080;"> 8</span> <span style="color: #800080;">$uid</span> = <span style="color: #800080;">$_REQUEST</span>['uid'<span style="color: #000000;">];</span><span style="color: #008080;"> 9</span> <span style="color: #800080;">$url_dir</span> = STATISTIC_EXPORT_FILE_DIR.<span style="color: #800080;">$uid</span> .'/';<span style="color: #008000;">//</span><span style="color: #008000;">@todo</span><span style="color: #008080;">10</span> <span style="color: #0000ff;">if</span>(!<span style="color: #008080;">is_dir</span>(<span style="color: #800080;">$url_dir</span><span style="color: #000000;">)){</span><span style="color: #008080;">11</span> @<span style="color: #008080;">mkdir</span>(<span style="color: #800080;">$url_dir</span>,0777<span style="color: #000000;">);</span><span style="color: #008080;">12</span> <span style="color: #000000;"> }</span><span style="color: #008080;">13</span> <span style="color: #800080;">$files</span> = <span style="color: #008080;">scandir</span>(<span style="color: #800080;">$url_dir</span><span style="color: #000000;">);</span><span style="color: #008080;">14</span> <span style="color: #008080;">15</span> <span style="color: #0000ff;">if</span>(!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$files</span><span style="color: #000000;">)){</span><span style="color: #008080;">16</span> <span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$files</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$key</span> => <span style="color: #800080;">$value</span><span style="color: #000000;">) {</span><span style="color: #008080;">17</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$value</span>!='.' && <span style="color: #800080;">$value</span>!='..'<span style="color: #000000;">){</span><span style="color: #008080;">18</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">substr</span>(<span style="color: #800080;">$value</span>, 0 , 5)=="flag_"<span style="color: #000000;">){</span><span style="color: #008080;">19</span> <span style="color: #800080;">$file_size</span> = <span style="color: #008080;">filesize</span>(<span style="color: #800080;">$url_dir</span> . <span style="color: #800080;">$value</span><span style="color: #000000;">);</span><span style="color: #008080;">20</span> <span style="color: #0000ff;">if</span>(!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$file_size</span><span style="color: #000000;">)){</span><span style="color: #008080;">21</span> <span style="color: #800080;">$fhandle</span> = <span style="color: #008080;">fopen</span>(<span style="color: #800080;">$url_dir</span> . <span style="color: #800080;">$value</span>, 'rb+'<span style="color: #000000;">);</span><span style="color: #008080;">22</span> <span style="color: #008080;">fseek</span>(<span style="color: #800080;">$fhandle</span>, -1,<span style="color: #000000;"> SEEK_END);</span><span style="color: #008080;">23</span> <span style="color: #800080;">$fstr</span> = ''<span style="color: #000000;">;</span><span style="color: #008080;">24</span> <span style="color: #0000ff;">while</span>((<span style="color: #800080;">$c</span> = <span style="color: #008080;">fgetc</span>(<span style="color: #800080;">$fhandle</span>)) !== <span style="color: #0000ff;">false</span><span style="color: #000000;">) {</span><span style="color: #008080;">25</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$c</span> == "\n" && <span style="color: #800080;">$fstr</span>) <span style="color: #0000ff;">break</span><span style="color: #000000;">;</span><span style="color: #008080;">26</span> <span style="color: #800080;">$fstr</span> = <span style="color: #800080;">$c</span> . <span style="color: #800080;">$fstr</span><span style="color: #000000;">;</span><span style="color: #008080;">27</span> <span style="color: #008080;">fseek</span>(<span style="color: #800080;">$fhandle</span>, -2,<span style="color: #000000;"> SEEK_CUR);</span><span style="color: #008080;">28</span> <span style="color: #000000;"> }</span><span style="color: #008080;">29</span> <span style="color: #008080;">fclose</span>(<span style="color: #800080;">$fhandle</span><span style="color: #000000;">);</span><span style="color: #008080;">30</span> <span style="color: #800080;">$fstr</span> = <span style="color: #008080;">trim</span>(<span style="color: #800080;">$fstr</span><span style="color: #000000;">);</span><span style="color: #008080;">31</span> <span style="color: #800080;">$fstr_arr_str</span> = <span style="color: #008080;">explode</span>(',', <span style="color: #800080;">$fstr</span><span style="color: #000000;">);</span><span style="color: #008080;">32</span> <span style="color: #800080;">$file_arr_process</span>[] = 100 * <span style="color: #008080;">number_format</span>(<span style="color: #800080;">$fstr_arr_str</span>[0]/<span style="color: #800080;">$fstr_arr_str</span>[1],2).'%'<span style="color: #000000;">;</span><span style="color: #008080;">33</span> <span style="color: #800080;">$file_arr_name</span>[] = <span style="color: #008080;">substr</span>(<span style="color: #800080;">$value</span>,5<span style="color: #000000;">);</span><span style="color: #008080;">34</span> <span style="color: #000000;"> }</span><span style="color: #008080;">35</span> <span style="color: #000000;"> }</span><span style="color: #008080;">36</span> <span style="color: #000000;"> }</span><span style="color: #008080;">37</span> <span style="color: #000000;"> }</span><span style="color: #008080;">38</span> <span style="color: #008080;">39</span> <span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$file_arr_process</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$key</span> => <span style="color: #800080;">$value</span><span style="color: #000000;">) {</span><span style="color: #008080;">40</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$value</span> != '100%'<span style="color: #000000;">){</span><span style="color: #008080;">41</span> <span style="color: #800080;">$refresh_flag</span> = 'no'<span style="color: #000000;">;</span><span style="color: #008080;">42</span> <span style="color: #0000ff;">break</span><span style="color: #000000;">;</span><span style="color: #008080;">43</span> <span style="color: #000000;"> }</span><span style="color: #008080;">44</span> <span style="color: #000000;"> }</span><span style="color: #008080;">45</span> <span style="color: #000000;"> }</span><span style="color: #008080;">46</span> <span style="color: #008080;">47</span> <span style="color: #800080;">$file_arr</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">(</span><span style="color: #008080;">48</span> 'process' => <span style="color: #800080;">$file_arr_process</span>,<span style="color: #008080;">49</span> 'name' => <span style="color: #800080;">$file_arr_name</span>,<span style="color: #008080;">50</span> 'refresh_flag' => <span style="color: #800080;">$refresh_flag</span><span style="color: #008080;">51</span> <span style="color: #000000;"> );</span><span style="color: #008080;">52</span> <span style="color: #800080;">$file_arr_json</span> = json_encode(<span style="color: #800080;">$file_arr</span><span style="color: #000000;">);</span><span style="color: #008080;">53</span> <span style="color: #0000ff;">echo</span> <span style="color: #800080;">$file_arr_json</span><span style="color: #000000;">;</span><span style="color: #008080;">54</span> }</span>View Code
五、下载文件
文件的下载就好说了,既然已经都生成成功,下载的方法如下:
<span style="font-family: 'Microsoft YaHei';"><span style="color: #008080;"> 1</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> execscript_download(){</span><span style="color: #008080;"> 2</span> <span style="color: #800080;">$filename</span> = <span style="color: #800080;">$_REQUEST</span>['filename'<span style="color: #000000;">];</span><span style="color: #008080;"> 3</span> <span style="color: #800080;">$uid</span> = <span style="color: #800080;">$_REQUEST</span>['uid'<span style="color: #000000;">];</span><span style="color: #008080;"> 4</span> <span style="color: #800080;">$file_dir</span> = STATISTIC_EXPORT_FILE_DIR.<span style="color: #800080;">$uid</span>.'/'.<span style="color: #800080;">$filename</span><span style="color: #000000;">;</span><span style="color: #008080;"> 5</span> <span style="color: #0000ff;">if</span> (!<span style="color: #008080;">file_exists</span>(<span style="color: #800080;">$file_dir</span><span style="color: #000000;">)){</span><span style="color: #008080;"> 6</span> <span style="color: #008080;">header</span>("Content-type: text/html; charset=utf-8"<span style="color: #000000;">);</span><span style="color: #008080;"> 7</span> <span style="color: #0000ff;">echo</span> "File not found!"<span style="color: #000000;">;</span><span style="color: #008080;"> 8</span> <span style="color: #0000ff;">exit</span><span style="color: #000000;">; </span><span style="color: #008080;"> 9</span> } <span style="color: #0000ff;">else</span><span style="color: #000000;"> {</span><span style="color: #008080;">10</span> <span style="color: #008080;">ini_set</span>("memory_limit","500M"<span style="color: #000000;">); </span><span style="color: #008080;">11</span> <span style="color: #008080;">header</span>('Content-Description: File Transfer'<span style="color: #000000;">);</span><span style="color: #008080;">12</span> <span style="color: #008080;">header</span>('Content-Type: application/octet-stream'<span style="color: #000000;">);</span><span style="color: #008080;">13</span> <span style="color: #008080;">header</span>('Content-Disposition: attachment; filename='.<span style="color: #008080;">basename</span>(<span style="color: #800080;">$file_dir</span><span style="color: #000000;">));</span><span style="color: #008080;">14</span> <span style="color: #008080;">header</span>('Content-Transfer-Encoding: binary'<span style="color: #000000;">);</span><span style="color: #008080;">15</span> <span style="color: #008080;">header</span>('Expires: ' . <span style="color: #008080;">gmdate</span>('D, d M Y H:i:s') . ' GMT'<span style="color: #000000;">);</span><span style="color: #008080;">16</span> <span style="color: #008080;">header</span>('Cache-Control: must-revalidate,post-check=0, pre-check=0'<span style="color: #000000;">);</span><span style="color: #008080;">17</span> <span style="color: #008080;">header</span>('Pragma: public'<span style="color: #000000;">);</span><span style="color: #008080;">18</span> <span style="color: #008080;">header</span>('Content-Length: ' . <span style="color: #008080;">filesize</span>(<span style="color: #800080;">$file_dir</span><span style="color: #000000;">));</span><span style="color: #008080;">19</span> <span style="color: #008080;">readfile</span>(<span style="color: #800080;">$file_dir</span><span style="color: #000000;">);</span><span style="color: #008080;">20</span> <span style="color: #000000;"> }</span><span style="color: #008080;">21</span> <span style="color: #008080;">22</span> }</span>
六、上线后出现的问题
本地本来已经测试完毕,可上线后,却出现了奇怪的问题;
现象描述:
当在后台点击生成文件,跳转到下载页的时候,因为下载页是显示文件进度的页面,
竟然出现有时候有刚刚点击的文件进度,有时候没有,就感觉没有生成相应的文件一样;解决方法:
因为数据文件和进度文件都是生成在程序的某个文件夹file中,所以读取的时候都是读取的文件夹下的文件,从而判断显示进度;
后面才知道,由于后台程序有两台服务器,导致读取以及下载的时候找不到相应的文件夹,两个服务器相应的文件夹弄个共享目录就可以了
七、相应的后续优化
由于下载的文件多了,导致文件夹下的文件越来越多,而原来生成的文件是没有价值的,所以加了个定期删除文件的功能,只保留近七天的文件
当然可以用crontab,只不过我比较懒,是在点击生成文件的时候,判断了一下文件夹中的过期文件,从而删除
<span style="font-family: 'Microsoft YaHei';"><span style="color: #008080;"> 1</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> execscript_process_show(){</span><span style="color: #008080;"> 2</span> <span style="color: #800080;">$this</span>->load->library('smarty'<span style="color: #000000;">);</span><span style="color: #008080;"> 3</span> <span style="color: #800080;">$uid</span> = <span style="color: #800080;">$_REQUEST</span>['uid'<span style="color: #000000;">];</span><span style="color: #008080;"> 4</span> <span style="color: #800080;">$url_dir</span> = STATISTIC_EXPORT_FILE_DIR.<span style="color: #800080;">$uid</span> .'/';<span style="color: #008000;">//</span><span style="color: #008000;">@todo</span><span style="color: #008080;"> 5</span> <span style="color: #0000ff;">if</span>(!<span style="color: #008080;">is_dir</span>(<span style="color: #800080;">$url_dir</span><span style="color: #000000;">)){</span><span style="color: #008080;"> 6</span> @<span style="color: #008080;">mkdir</span>(<span style="color: #800080;">$url_dir</span>,0777<span style="color: #000000;">);</span><span style="color: #008080;"> 7</span> <span style="color: #000000;"> } </span><span style="color: #008080;"> 8</span> <span style="color: #800080;">$files</span> = <span style="color: #008080;">scandir</span>(<span style="color: #800080;">$url_dir</span><span style="color: #000000;">);</span><span style="color: #008080;"> 9</span> <span style="color: #0000ff;">if</span>(!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$files</span><span style="color: #000000;">)){</span><span style="color: #008080;">10</span> <span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$files</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$key</span> => <span style="color: #800080;">$value</span><span style="color: #000000;">) {</span><span style="color: #008080;">11</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$value</span>!='.' && <span style="color: #800080;">$value</span>!='..'<span style="color: #000000;">){</span><span style="color: #008080;">12</span> <span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$files</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$key</span> => <span style="color: #800080;">$value</span><span style="color: #000000;">) {</span><span style="color: #008080;">13</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$value</span>!='.' && <span style="color: #800080;">$value</span>!='..'<span style="color: #000000;">){</span><span style="color: #008080;">14</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">substr</span>(<span style="color: #800080;">$value</span>, 0 , 5)!="flag_"<span style="color: #000000;">){</span><span style="color: #008080;">15</span> <span style="color: #800080;">$filenamedate</span> = <span style="color: #008080;">substr</span>(<span style="color: #800080;">$value</span>, 0,10<span style="color: #000000;">);</span><span style="color: #008080;">16</span> <span style="color: #800080;">$today</span> = <span style="color: #008080;">date</span>('Y-m-d',<span style="color: #008080;">time</span><span style="color: #000000;">());</span><span style="color: #008080;">17</span> <span style="color: #800080;">$filenamedate</span> = <span style="color: #008080;">date</span>('Y-m-d',<span style="color: #008080;">strtotime</span>(<span style="color: #800080;">$filenamedate</span>)+(STATISTIC_FILE_EXPIRE_DAY-1)*24*3600<span style="color: #000000;">);</span><span style="color: #008080;">18</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$today</span>><span style="color: #800080;">$filenamedate</span>){<span style="color: #008000;">//</span><span style="color: #008000;">文件过期</span><span style="color: #008080;">19</span> @<span style="color: #008080;">unlink</span>(<span style="color: #800080;">$url_dir</span> . <span style="color: #800080;">$value</span><span style="color: #000000;">);</span><span style="color: #008080;">20</span> @<span style="color: #008080;">unlink</span>(<span style="color: #800080;">$url_dir</span> . 'flag_' . <span style="color: #800080;">$value</span><span style="color: #000000;">);</span><span style="color: #008080;">21</span> <span style="color: #000000;"> }</span><span style="color: #008080;">22</span> <span style="color: #000000;"> }</span><span style="color: #008080;">23</span> <span style="color: #000000;"> }</span><span style="color: #008080;">24</span> <span style="color: #000000;"> } </span><span style="color: #008080;">25</span> <span style="color: #000000;"> }</span><span style="color: #008080;">26</span> <span style="color: #000000;"> }</span><span style="color: #008080;">27</span> <span style="color: #000000;"> }</span><span style="color: #008080;">28</span> <span style="color: #008080;">29</span> <span style="color: #800080;">$this</span>->smarty->assign('uid',<span style="color: #800080;">$uid</span><span style="color: #000000;">);</span><span style="color: #008080;">30</span> <span style="color: #800080;">$this</span>->smarty->display('interact/statistic/execscript.tpl'<span style="color: #000000;">);</span><span style="color: #008080;">31</span> }</span>
八、后记
大文件的导出大体就是这个样子,欢迎大家吐槽,共同交流;
当时在用命令行执行方法的时候,也参考了一下相应的资料,记录一下;
<span style="color: #000000; font-family: 'Microsoft YaHei';">http://blog.csdn.net/yysdsyl/article/details/4636457http://www.codesky.net/article/201202/163385.htmlhttp://www.cnblogs.com/zdz8207/p/3765567.htmlhttp:[email protected]/blog/static/4112219320097300922992/http://php.net/manual/en/features.commandline.phphttp://blog.csdn.net/yangjun07167/article/details/5603425http://blog.csdn.net/yunsongice/article/details/5445448http://www.cppblog.com/amazon/archive/2011/12/01/161281.aspxhttp://blog.51yip.com/tag/proc_openhttp://www.justwinit.cn/post/1418/http://limboy.me/tech/2010/12/05/php-async.html</span>
- 4楼Shannon
- 我目前在用的导出Excel使用了MS的Excel, 需要配置DCOM.,先导出XML格式,再将XML格式转换为Excel格式, 超过50000行自动换页,,在IIS中设置允许最大800M的下载, 导出几年的交易记录毫无压力.,Excel文件超过4M,自动使用7Z压缩.,,使用VBScript, 可以在Windows平台直接运行.
- Re: 糖糖果
- @Shannon,厉害!如果文件特别大的话,确实应该考虑文件下载的大小限制以及文件的压缩,,也确实是下一步优化的思路,学习了。。。
- 3楼zjeagle
- 个人认为大文件还用table的html格式,那叫耍流氓。,文件不是一般的大。
- Re: longware
- @zjeagle,csv伺候,小一半
- Re: 糖糖果
- @zjeagle,哈哈...这个确实了,还是那个office07打开的问题记得,所以最终还是用了table,不过用table确实不是很好的办法
- 2楼zjeagle
- csv还是太大了。,建议考虑标准的excel格式,用aspose.cells或者npoi之类吧。
- Re: 糖糖果
- @zjeagle,确实,有些生成的excel的工具,格式都生成的好,并且也很漂亮,满足的格式也多。。。
- 1楼zsea
- 曾经也遇到过大量数据导出Excel,还不许用csv,最后是自己写的导出的功能,一次能导出好几十万条记录到Excel,速度还可以。
- Re: 糖糖果
- @zsea,哈哈,我也遇到过,有些需求实在是变态,本来能很容易的实现,却不让用。。。

“你的组织要求你更改PIN消息”将显示在登录屏幕上。当在使用基于组织的帐户设置的电脑上达到PIN过期限制时,就会发生这种情况,在该电脑上,他们可以控制个人设备。但是,如果您使用个人帐户设置了Windows,则理想情况下不应显示错误消息。虽然情况并非总是如此。大多数遇到错误的用户使用个人帐户报告。为什么我的组织要求我在Windows11上更改我的PIN?可能是您的帐户与组织相关联,您的主要方法应该是验证这一点。联系域管理员会有所帮助!此外,配置错误的本地策略设置或不正确的注册表项也可能导致错误。即

Windows11将清新优雅的设计带到了最前沿;现代界面允许您个性化和更改最精细的细节,例如窗口边框。在本指南中,我们将讨论分步说明,以帮助您在Windows操作系统中创建反映您的风格的环境。如何更改窗口边框设置?按+打开“设置”应用。WindowsI转到个性化,然后单击颜色设置。颜色更改窗口边框设置窗口11“宽度=”643“高度=”500“>找到在标题栏和窗口边框上显示强调色选项,然后切换它旁边的开关。若要在“开始”菜单和任务栏上显示主题色,请打开“在开始”菜单和任务栏上显示主题

默认情况下,Windows11上的标题栏颜色取决于您选择的深色/浅色主题。但是,您可以将其更改为所需的任何颜色。在本指南中,我们将讨论三种方法的分步说明,以更改它并个性化您的桌面体验,使其具有视觉吸引力。是否可以更改活动和非活动窗口的标题栏颜色?是的,您可以使用“设置”应用更改活动窗口的标题栏颜色,也可以使用注册表编辑器更改非活动窗口的标题栏颜色。若要了解这些步骤,请转到下一部分。如何在Windows11中更改标题栏的颜色?1.使用“设置”应用按+打开设置窗口。WindowsI前往“个性化”,然

您是否在Windows安装程序页面上看到“出现问题”以及“OOBELANGUAGE”语句?Windows的安装有时会因此类错误而停止。OOBE表示开箱即用的体验。正如错误提示所表示的那样,这是与OOBE语言选择相关的问题。没有什么可担心的,你可以通过OOBE屏幕本身的漂亮注册表编辑来解决这个问题。快速修复–1.单击OOBE应用底部的“重试”按钮。这将继续进行该过程,而不会再打嗝。2.使用电源按钮强制关闭系统。系统重新启动后,OOBE应继续。3.断开系统与互联网的连接。在脱机模式下完成OOBE的所

任务栏缩略图可能很有趣,但它们也可能分散注意力或烦人。考虑到您将鼠标悬停在该区域的频率,您可能无意中关闭了重要窗口几次。另一个缺点是它使用更多的系统资源,因此,如果您一直在寻找一种提高资源效率的方法,我们将向您展示如何禁用它。不过,如果您的硬件规格可以处理它并且您喜欢预览版,则可以启用它。如何在Windows11中启用任务栏缩略图预览?1.使用“设置”应用点击键并单击设置。Windows单击系统,然后选择关于。点击高级系统设置。导航到“高级”选项卡,然后选择“性能”下的“设置”。在“视觉效果”选

在Windows11上的显示缩放方面,我们都有不同的偏好。有些人喜欢大图标,有些人喜欢小图标。但是,我们都同意拥有正确的缩放比例很重要。字体缩放不良或图像过度缩放可能是工作时真正的生产力杀手,因此您需要知道如何对其进行自定义以充分利用系统功能。自定义缩放的优点:对于难以阅读屏幕上的文本的人来说,这是一个有用的功能。它可以帮助您一次在屏幕上查看更多内容。您可以创建仅适用于某些监视器和应用程序的自定义扩展配置文件。可以帮助提高低端硬件的性能。它使您可以更好地控制屏幕上的内容。如何在Windows11

屏幕亮度是使用现代计算设备不可或缺的一部分,尤其是当您长时间注视屏幕时。它可以帮助您减轻眼睛疲劳,提高易读性,并轻松有效地查看内容。但是,根据您的设置,有时很难管理亮度,尤其是在具有新UI更改的Windows11上。如果您在调整亮度时遇到问题,以下是在Windows11上管理亮度的所有方法。如何在Windows11上更改亮度[10种方式解释]单显示器用户可以使用以下方法在Windows11上调整亮度。这包括使用单个显示器的台式机系统以及笔记本电脑。让我们开始吧。方法1:使用操作中心操作中心是访问

Windows上的激活过程有时会突然转向显示包含此错误代码0xc004f069的错误消息。虽然激活过程已经联机,但一些运行WindowsServer的旧系统可能会遇到此问题。通过这些初步检查,如果这些检查不能帮助您激活系统,请跳转到主要解决方案以解决问题。解决方法–关闭错误消息和激活窗口。然后,重新启动计算机。再次从头开始重试Windows激活过程。修复1–从终端激活从cmd终端激活WindowsServerEdition系统。阶段–1检查Windows服务器版本您必须检查您使用的是哪种类型的W


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
