简体   繁体   English

同时调用同一文件时php阻塞

[英]php blocking when calling the same file concurrently

i'm having some really strange problem. 我有一些很奇怪的问题。

i wrote a filemanager in PHP with the ability to download files -- which works fine. 我用PHP编写了一个文件管理器,它具有下载文件的功能-效果很好。 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. 下载完成后,一切都会恢复。

is there something that prevents PHP from parsing the same file concurrently? 是否有某些东西可以阻止PHP同时解析同一文件? because other scripts work like a charm, no matter if i'm downloading or not. 因为无论我是否下载,其他脚本都像超级按钮一样工作。

help or links to documentation are highly appreciated :) 帮助或文档链接受到高度赞赏:)

Do you use sessions? 您是否使用会话?

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. 实际上,这意味着每个用户都按顺序执行PHP文件。 To solve this you must use a custom session handler that uses a DB. 为了解决这个问题,您必须使用使用数据库的自定义会话处理程序。 Read this . 阅读

Edit: 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! 如果需要,请阅读有关此内容的更多文档!

Edit 2: Sometimes using session_write_close() to close the session when no longer needed is enough (see the comments). 编辑2:有时在不再需要时使用session_write_close()关闭会话(请参见注释)。

Daremon is correct, but you shouldn't need to use a different session handler. Daremon是正确的,但是您不需要使用其他会话处理程序。 If you call session_write_close() before you start sending the file, the lock on the session file will be released and your other scripts should be able to continue. 如果在开始发送文件之前调用session_write_close() ,则会话文件上的锁将被释放,您的其他脚本应该可以继续。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM