1.需要session控制的大文件下载,防止因为占用session文件时间太久,导致其他页面的session无法执行

session_write_close() worked as a lifesaver for me when automatically uploading files to a user (forcing a download instead of a link). If files are large, and since session_start() does not allow another page using session_start() to proceed until it's done, i was not able to upload more than one file at a time. By using session_write_close() before beginning the file upload, my users can now download as many big files as they like, at the same time. Example:
<?
session_start();
/* Do session stuff here; security; logging; etc. */
session_write_close();
/* NOW write out the requested file. */
header("Content-type: audio/x-mpeg"); /* or whatever type */
header("Content-Disposition: attachment; filename=" . $filename);
header("Content-Length: " . $filesize);
header("Content-Transfer-Encoding: binary\n\n");
header("Pragma: no-cache");
header("Expires: 0");
$file_contents = file_get_contents($filepath);
print($file_contents);
?>

2.保存当前的session变化,防止由于header页面跳转导致修改的session内容没有保存,被丢失

This
function is essencial when you change $_SESSION[] variables and then,
at some poit in the middle of the script, you send an header("Location: )
function to the browser, because in this case the session variables may
not be saved before the browser change to the new page.
To prevent
from lossing session data, allways use session_write_close before this
header function. session_write_close will force session data to be saved
before the browser change to the new page.
Hope this will help you
not to loose 1 day wondering why people could not authenticate or make
other changes in session vars in your site.

session_write_close() 用法的更多相关文章

  1. CI session 类的用法

    最近使用codeingiter框架,发现默认的session 不是很好用,以下是用法总结:使用的是2.0.2的版本 1.扩展自带的session类:application/libraries/MY_s ...

  2. EditText 基本用法

    title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...

  3. jquery插件的用法之cookie 插件

    一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...

  4. Java中的Socket的用法

                                   Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...

  5. [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法

    一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...

  6. python enumerate 用法

    A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...

  7. [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结

    本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...

  8. 【JavaScript】innerHTML、innerText和outerHTML的用法区别

    用法: <div id="test">   <span style="color:red">test1</span> tes ...

  9. chattr用法

    [root@localhost tmp]# umask 0022 一.chattr用法 1.创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件 [root@localhost tmp] ...

随机推荐

  1. css3同心圆闪烁扩散效果

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. docker之安装和基本使用(一)

    前言 开始折腾docker. 主要概念 容器:独立运行的一个或一组应用,与其他应用完全独立. 镜像:用于创建 Docker容器的模板. 仓库:用于收纳镜像文件,可以理解为代码控制中的代码仓库 注意: ...

  3. python3-可变和不可变数据类型

    可变:[ ]    { } 不可变:int    str   ( )     应用实例: 把列表l,追加到列表s中,现在网列表l中追加一个5,打印列表s可以看到,列表s中的列表l中也有5. d={&q ...

  4. Linux端口占用

    1.netstat netstat -anp | grep 23232 Sample: [root@BICServer 0825]# netstat -anp | grep 23232 tcp 0 0 ...

  5. SQLite3 使用教学

    source: SQL中文站:http://www.sqlite.com.cn/MySqlite/4/378.Html OS X自从10.4后把SQLite这套相当出名的数据库软件,放进了作业系统工具 ...

  6. ProxySQL 排错 Max connect timeout reached while reaching hostgroup 10 after 10000ms

    ProxySQL 排错 问题分析: 在ProxySQL在集群下,因未知原因导致误测到所有节点OFFLINE_HARD,并runtime_mysql_servers表清空,从而导致前端查询无法传递到后端 ...

  7. NFS生产场景优化

    1.硬件上多块网卡bond,增加吞吐量,至少千兆.sas/ssd磁盘组raid5或raid10 2.服务端配置:/data 172.16.1.0/24(rw,sync,all_squash,anonu ...

  8. java版云笔记(五)

    下来是创建笔记本,创建笔记,这个没什么难点和前面是一样的. 创建笔记本 首先点击"+"弹出添加笔记的对话框,然后点击确定按钮创建笔记本. //点击"+"弹出添加 ...

  9. 苹果容器超出内容overflow滑动卡顿问题

    -webkit-overflow-scrolling:touch; 就这么一段代码,加载需要滚动的容器css样式中.因为苹果的硬件加速产生的后果....

  10. java基础4 函数

    本文知识点(目录): 1.函数的概述    2.函数的格式    3.自定义函数    4.函数的特点    5.函数的应用    6.函数的重载 1.函数的概述 发现不断进行加法运算,为了提高代码的 ...