<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>爱周末 &#187; php session</title>
	<atom:link href="http://zhoumo123.cn/tag/php-session/feed" rel="self" type="application/rss+xml" />
	<link>http://zhoumo123.cn</link>
	<description>知识分享，共同进步。zhoumo123.cn</description>
	<lastBuildDate>Thu, 07 Nov 2019 05:53:49 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0.1</generator>
	<item>
		<title>php session_start 异步加载页面慢session_write_close()函数解决办法</title>
		<link>http://zhoumo123.cn/php/3076.html</link>
		<comments>http://zhoumo123.cn/php/3076.html#comments</comments>
		<pubDate>Thu, 02 Jul 2015 09:34:51 +0000</pubDate>
		<dc:creator><![CDATA[zhangc]]></dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[php session]]></category>
		<category><![CDATA[session_write_close()]]></category>

		<guid isPermaLink="false">http://zhoumo123.cn/?p=3076</guid>
		<description><![CDATA[PHP页面中存在 session_start()与异步加载数据时，页面会很慢，什么原因呢，导致原因为php session 堵塞，使用session过程中，在开启session后，同一浏览器，执行同一程序，不同页面会被锁。不同浏览器不会出现这种情况。一起看下解决办法。 查了下PHP的Bug列表，发现有人提出了这个问题： Description: &#8212;&#8212;&#8212;&#8212; Calling session_start() appears to wait until other scripts have exited that are using the same s ...  <a href="http://zhoumo123.cn/php/3076.html">  阅读全文 </a>]]></description>
				<content:encoded><![CDATA[<p>PHP页面中存在 session_start()与异步加载数据时，页面会很慢，什么原因呢，导致原因为php session 堵塞，使用session过程中，在开启session后，同一浏览器，执行同一程序，不同页面会被锁。不同浏览器不会出现这种情况。一起看下解决办法。</p>
<p>查了下PHP的Bug列表，发现有人提出了这个问题：</p>
<p>Description:<br />
&#8212;&#8212;&#8212;&#8212;<br />
Calling session_start() appears to wait until other scripts have exited</p>
<p>that are using the same session. My guess is the 1st request locks the<br />
session file for exclusive use, and the second request blocks until it<br />
can open it.</p>
<p>PHP官方的回复是：</p>
<p>Thank you for taking the time to write to us, but this is not a bug.This is expected, the session file is locked to avoid corruption.</p>
<p>结合了PHP的Session机制，找到了阻塞的原因。由于PHP的Session信息是写入文件的，1个客户端占有1个session文件。因此，当 session_start被调用的时候，该文件是被锁住的，而且是以读写模式锁住的（因为程序中可能要修改session的值），这样，第2次调用 session_start的时候就被阻塞了。</p>
<p>最简解决方法：</p>
<p>查了PHP的手册，发现一个session_write_close函数，作用是Write session data and end session，也就是写session的数据，同时关闭这个session。因此，我们可以在用完session之后，调用这个函数关闭session 文件即可解除锁定。一般，session是用来记录用户身份信息的，以便PHP进行身份认证，因此完全可以将session的读写放在页面刚开始执行的时 候，在执行完以后，马上调用session_write_close函数即可。</p>
<p><strong>使用 <span style="color: #ff0000;">session_write_close()</span> 方法 例如</strong></p>
<p><strong>session_start();</strong><br />
<strong>$_SESSION[$name] = $name;</strong><br />
<strong>session_write_close(); //或者 session_commit();</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://zhoumo123.cn/php/3076.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Session可能会引起并发问题session锁</title>
		<link>http://zhoumo123.cn/php/3015.html</link>
		<comments>http://zhoumo123.cn/php/3015.html#comments</comments>
		<pubDate>Fri, 26 Jun 2015 03:33:12 +0000</pubDate>
		<dc:creator><![CDATA[zhangc]]></dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[php session]]></category>

		<guid isPermaLink="false">http://zhoumo123.cn/?p=3015</guid>
		<description><![CDATA[在进行Web应用程序开发的时候，人们经常会用Session存储数据。但可能有人不知道，在PHP中，Session使用不当可能会引起并发问题。印度医疗行业软件解决方案提供商Plus91 Technologies高级工程师Kishan Gor在个人博客上对这个问题进行了阐释。 如果同一个客户端并发发送多个请求，而每个请求都使用了Session，那么PHP Session锁的存在会导致服务器串行响应这些请求，而不是并行。这是因为在默认情况下，PHP使用文件存储Session数据。对于每一个新的Session，PHP会创建一个文件，并持续向其中写入数据。所以，每次调用session_start（）方法 ...  <a href="http://zhoumo123.cn/php/3015.html">  阅读全文 </a>]]></description>
				<content:encoded><![CDATA[<p>在进行Web应用程序开发的时候，人们经常会用Session存储数据。但可能有人不知道，在PHP中，Session使用不当可能会引起并发问题。印度医疗行业软件解决方案提供商Plus91 Technologies高级工程师Kishan Gor在个人博客上对这个问题进行了阐释。</p>
<p>如果同一个客户端并发发送多个请求，而每个请求都使用了Session，那么PHP Session锁的存在会导致服务器串行响应这些请求，而不是并行。这是因为在默认情况下，PHP使用文件存储Session数据。对于每一个新的Session，PHP会创建一个文件，并持续向其中写入数据。所以，每次调用session_start（）方法，就会打开Session文件，并取得文件的独占锁。这样，如果服务器脚本正在处理一个请求，而客户端又发送了一个同样需要使用Session的请求，那么后一个请求会阻塞，直至前一个请求处理完成释放了文件上的独占锁。不过，这只限于来自同一个客户端的多个请求，也就是说，来自一个客户端的请求并不会阻塞另一个客户端的请求。</p>
<p>如果脚本很短，这通常没有问题。但如果脚本运行时间比较长，那就可能会产生问题。在现代Web应用程序开发中，有一个非常常见的情况，就是使用AJAX技术在同一个页面内发送多个请求获取数据。如果这些请求都需要使用Session，那么第一个请求到达服务器后会取得Session锁，其它请求就必须等待，所有请求将串行处理，即使它们彼此之间并没有依赖关系。这将大大增加页面的响应时间。</p>
<p>有一个方法可以避免这个问题，就是在使用完Session以后立即调用session_write_close（）方法关闭Session。这样Session锁就会释放，即使当前脚本还在等在处理。需要注意的是，调用该方法后，当前脚本就不能进一步操作Session了。</p>
<p>需要特别指出的是，本文所陈述的问题和观点只适用于使用session_start（）方法的PHP默认Session管理模式。比如，有用户就指出，如果将应用程序托管在AWS EC2上，并正确配置DynamoDB，Session锁定问题就不会出现。</p>
<p>http://www.cnblogs.com/rrsina/p/4594610.html</p>
]]></content:encoded>
			<wfw:commentRss>http://zhoumo123.cn/php/3015.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
