php blocking when calling the same file concurrently

一曲冷凌霜 提交于 2019-12-02 02:40:26

问题


i'm having some really strange problem.

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.

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 :)


回答1:


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. 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:


Daremon is correct, but you shouldn't need to use a different session handler. 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.



来源:https://stackoverflow.com/questions/1174378/php-blocking-when-calling-the-same-file-concurrently

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!