Jump to content

Question on will php finish one request before starting another?


cpthk

Recommended Posts

Hi:

 

I trying to write a php code. That it will first write to a file(for instance: dynamically create a pdf file) with same filename. After finish writing, it will prompt user to download. My question is if first user is still downloading the file. That's assume the file is pretty big. And a second user run this php file too. What will happen that one is downloading this file and the other is writing this file? Will php finish one request before starting another?

 

PS: I understand that I can write each time to a different filename. But I am trying to write into the same file is because I don't want the server' hard drive one day is full of this file.

 

Thanks.

Link to comment
Share on other sites

php does it all the time with images without an issue.

 

The way to properly create dynamic file downs is

 

1) Get the data be it a binary, image file unresized, pdf stuff etc.

2) Place said data in a variable

3) Set headres of the document so that it reflects the files name, size, extension and a download prompt (see the php,net headers function)

4) Place the data in step 2 in to the file's content via an echo or some other manner and your done.

Link to comment
Share on other sites

Thanks for your help. So you are saying php will cache the file in memory and run without any problem?

 

The create dynamic file works for pdf too? I thought it only works for text file, since pdf content is compressed. Just like you open a pdf file in notepad, you will see like random texts. Does dynamic create file work with pdf, too? Any tutorial?

 

Thanks again.

Link to comment
Share on other sites

you can make any type of file , the thing is php doesn't have to make a "document" you could in theroy write a C linker/compiler and so forth to write C in a web browser form and then compile it to an .exe file you could download.  As long as your file content agrees with what that file is suppose to do.

Most of the time the best way is to take the binary safe of the files content (using File_get_content($fileanme,BINARY_SAFE)) and then store it in mysql and recall on demand.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.