2

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
  • How are you forcing the download? Commented Jul 23, 2009 at 20:55

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

5 Comments

Wow, never knew that.. but it sounds likely to be the problem.
that sounds reasonable. but sessions are closed before sending content, aren't they? and i can't/don't want to use a DB for this -- it's php-only.
call session_write_close() once you have finished using the session (i.e. before sending the file). that will release the lock
How do you push the files? I suspect you do something like: session_start(); readfile($file_path); which would be a problem
tom haigh: i actually thought of that too. i'm trying it out at the moment. daremon: why is that a problem?
1

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.

1 Comment

Indeed in this case just closing the session before pushing the file is better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.