PHP脚本调用AJAX不能执行start_session() [英] PHP script called by ajax can't execute start_session()

查看:111
本文介绍了PHP脚本调用AJAX不能执行start_session()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调用在session_start()顶部,并创建一些会话变量一个脚本中。 然后,这个脚本调用Ajax调用脚本B:

I have a script A that calls session_start() at the top and creates some session variables. Then the script makes an ajax call that invokes script B:

$("#galleryContent").load("B.php", {op : 'get_thumbs' 
                                   },
                                   function() {
                                    $('.galleryThumb').draggable(thumb_dragOps);  
                                   }
                         s);  

B需要访问会话变量脚本中设置,以便它确实在session_start(),试图获得的变量。但是B的在session_start()挂起。

B needs access to the session variables script A set up so it does a session_start() to try to get at the variables. But B's session_start() hangs.

难道我做错了吗?

感谢

推荐答案

这是由于锁定; PHP锁定会话文件同时写入到它。为了解决这个问题,关闭会话文件,当您完成使用的 session_write_close()

It's due to locking; PHP locks the session file while it is writing to it. To fix this, close the session file when you are done modifying session variables using session_write_close().

我曾在过去的正是这个问题,并锁定了这个问题。只是一定要明确地告诉PHP你就大功告成了修改使用 session_write_close()的会议,你应该就可以了。

I have had exactly this problem in the past, and locking was the problem. Just be sure to explicitly tell PHP you're done modifying the session using session_write_close(), and you should be fine.

文档

会话数据通常存储在您的脚本之后,无需调用 session_write_close(),但作为会话数据被锁定为prevent并发写入只有一个脚本终止可以在一个会话在任何时候进行操作。当使用框架连同会议您将体验到装载逐一帧由于这种锁。您可以等到所有修改会话变量完成结束会话减少加载所有帧所需的时间。

Session data is usually stored after your script terminated without the need to call session_write_close(), but as session data is locked to prevent concurrent writes only one script may operate on a session at any time. When using framesets together with sessions you will experience the frames loading one by one due to this locking. You can reduce the time needed to load all the frames by ending the session as soon as all changes to session variables are done.

注意:您还可以设置自定义会话处理程序并完全由存储会话信息在数据库中避免这种情况的文件锁定问题。在任何一种规模,这是pretty的太大的必要。

Note: You can also set up a custom session handler and avoid this file-locking problem entirely by storing session information in a database. At any kind of scale, this is pretty much a necessity.

这篇关于PHP脚本调用AJAX不能执行start_session()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆