问题描述
我遇到了一些非常奇怪的问题.
i'm having some really strange problem.
我用PHP编写了一个文件管理器,它具有下载文件的能力-效果很好.整个脚本被构建为一个大文件.
i wrote a filemanager in PHP with the ability to download files -- which works fine.the whole script is built as one big file.
现在,在下载大文件时,我无法同时使用脚本来浏览文件夹内容.它什么也没做,只是继续加载.下载完成后,一切都会恢复正常.
now, while downloading a big file i'm not able to use the script at the same time for, say, browsing folder contents. it does nothing but keep loading. as soon as the download is finished everything works again.
是否有某些东西可以阻止PHP同时解析同一文件?因为无论我是否下载,其他脚本都像超级按钮一样工作.
is there something that prevents PHP from parsing the same file concurrently? because other scripts work like a charm, no matter if i'm downloading or not.
帮助或文档链接非常受人们欢迎:)
help or links to documentation are highly appreciated :)
推荐答案
您使用会话吗?
如果是,那么可能是问题所在.默认的会话处理程序使用在执行启用会话的代码时必须锁定的文件.实际上,这意味着每个用户都按顺序执行PHP文件.为了解决这个问题,您必须使用使用数据库的自定义会话处理程序.阅读此.
If yes, then that's probably the problem. The default session handler uses files which have to be locked while session-enabled code is executed. Practically this means that each user executes PHP files sequentially. To solve this you must use a custom session handler that uses a DB. Read this.
我想指出,编写没有锁定的自定义会话处理程序可能很困难,并且会引入各种细微的错误.如果需要,请阅读有关此内容的更多文档!
I want to point out that writing a custom session handler with no locking can be difficult and introduce various subtle bugs. Read more docs on this if you need to do it!
有时在不再需要时使用session_write_close()关闭会话(请参见注释).
Edit 2: Sometimes using session_write_close() to close the session when no longer needed is enough (see the comments).
这篇关于并发调用同一文件时php阻塞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!