Double Submit with File Upload

Hello!

I’m trying to implement a file upload script, and the process seems pretty straightforward:

 <form action="../main_scripts/process_insert_update_file.php" method="post" enctype="multipart/form-data"  >
    <label for="filelabel">File to upload (2 MB max):  <input name="uploadedfile" type="file" /></label>
   <input type="hidden" name="MAX_FILE_SIZE" value="2097152"/> <input type="hidden" name="action" value="upload"/>
      <input type="submit" value="Submit" />
</form>

(Of course I’ll be doing plenty of validation after submission)

As a start, I’m just hitting submit, and then printing the values of $_FILES in my process script. What I’m finding is that both locally or on my production server, if I do a bunch of these submits in a row (in other words, submit –>look at my $_FILES array–>do this again with another file), that rather quickly, I’ll need to double submit or php gets stuck. Might there be an explanation for this in terms of how php allocates memory? And if so, is there anyway around this?

Thank you for your help,

Eric

Can you provide a sample of your output per submission?

For example in the format of:
submit file.txt
$_FILES[‘tmp_name’] = “/tmp/file.txt” // or provide the output of var_dump($_FILES)

then submit file2.txt
$_FILES[‘tmp_name’] = “/tmp/file2.txt” // or provide the output of var_dump($_FILES)

etc.

As I’m not sure I am following your question.

Here’s an example of the output:

Array
(
    [uploadedfile] => Array
        (
            [name] => GermanSupport.docx
            [type] => application/vnd.openxmlformats-officedocument.wordprocessingml.document
            [tmp_name] => /Applications/MAMP/tmp/php/phpziMQaz
            [error] => 0
            [size] => 310174
        )

)

Sorry if the issue isn’t clear! Basically, I submit a file, take a quick look at my output, then try to upload another file. If I do a bunch of these in a row, I’m finding that php stalls. If you note, this particular file isn’t really big so there should be an issue.

-Eric

Can you elaborate on php stalls? Meaning the upload never completes, so you don’t see an output page? Or is there a different meaning?

I think I’m starting to get an idea of what you are trying to say, I just want to make sure I look in the right direction before troubleshooting it :wink:

Basically I wait for at least 20 seconds before giving up: so it never loads completely! :). For such a small file on a local server, the “upload” should be instantaneous, no?

Yes, it should. My gut says this may be an Apache or IIS issue and not PHP.

Which one are you using and are you running it on a *nix/Mac or Windows box?

I just ran several tests on Linux Apache setup and never got a single hang up. So I’m leaning towards your Apache or IIS configuration being the culprit. You may want to ensure logging is turned on and watch your logs on each request.

Thank you for giving the issue more thought. I checked out my Apache Log (I have a Mac and am using MAMP) and got:

Nov 21 15:51:15 Macintosh-78 mDNSResponder[27]: PenaltyTimeForServer: PenaltyTime negative -13238, (server penaltyTime -1260237391, timenow -1260224153) resetting the penalty

during one of the “stuck loads”.

Hmm… that is an odd error message in your apache log, I’d try changing your ntp server as described at https://discussions.apple.com/thread/2726460?start=0&tstart=0 and http://www.dummies.com/how-to/content/how-to-synchronize-time-in-preparation-for-lion-se.html

Be sure to restart apache after changing the ntp server. If that doesn’t make it go away, I’ll still be doing more digging, but if you could give us more of the apache log (like a section of it that also contains the penaltytimeforserver error, that may help.

You may have to restart your computer for the new ntp server to take effect too (I forgot to mention this in my earlier post)

Cool! I’ll check out the links. In the meantime, my log looks like:

Nov 21 15:50:02 Macintosh-78 SecurityAgent[631]: de.appsolute.runServers|2012-11-21 15:50:02 -0800
Nov 21 15:50:02 Macintosh-78 com.apple.WindowServer[58]: Wed Nov 21 15:50:02 Macintosh-78.local WindowServer[58] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
Nov 21 15:50:02 Macintosh-78 WindowServer[58]: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
Nov 21 15:51:15 Macintosh-78 mDNSResponder[27]: PenaltyTimeForServer: PenaltyTime negative -13238, (server penaltyTime -1260237391, timenow -1260224153) resetting the penalty
Nov 21 15:56:16 Macintosh-78 Safari[513]: Periodic CFURLCache Insert stats (iters: 361) - Tx time:0.189981, # of Inserts: 23, # of bytes written: 7525, Did shrink: NO, Size of cache-file: 144932864, Num of Failures: 0
Nov 21 15:56:16 Macintosh-78 WebProcess[515]: Periodic CFURLCache Insert stats (iters: 360) - Tx time:0.011868, # of Inserts: 1, # of bytes written: 216652, Did shrink: NO, Size of cache-file: 145154048, Num of Failures: 0
Nov 21 16:13:29 Macintosh-78 mdworker32[716]: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
Nov 21 16:17:02 Macintosh-78 Safari[513]: IPCClient: Server port 0 is invalid; looking it up again…

However…if nothing jumps out at you, I think that I may just ignore this error as long as it works on my production server. :slight_smile:

Any final pre-Thanksgiving thoughts based on the above?

-Eric

OK…I followed the instructions in the link, will restart AND cross my fingers!

Hello!

I did the restart and got a different message this time around:

Nov 21 16:39:28 Macintosh-78 Safari Webpage Preview Fetcher[514]: INSERT-HANG-DETECTED: Tx time:4.856969, # of Inserts: 1, # of bytes written: 2907, Did shrink: NO
Nov 21 16:39:39 Macintosh-78 Safari Webpage Preview Fetcher[514]: INSERT-HANG-DETECTED: Tx time:5.920149, # of Inserts: 5, # of bytes written: 237676, Did shrink: NO
Nov 21 16:43:25 Macintosh-78 Safari[510]: IPCClient: Server port 0 is invalid; looking it up again…

At least it seems a little bit more descriptive (Insert-hang-detected???). Regardless, I fear that based on what you’ve said, this may be a Mac/local Apache issue and it’s beginning to feel a little bit like a Black Hole of Doom. So…I’m going to play around with file uploads to my real-deal server, and unless things are still funky (I can’t image why they would be!), I’ll consider this matter closed.

Regardless, I appreciate your time and enjoy your Thanksgiving!

-Eric

Yep, that seems to definitely point to the Mac/Apache setup, primarily pointing at Safari (have you tried a different browser after quitting safari? - Preferably one that doesn’t use webkit). Another idea is to disable any and all plugins you may have in Safari and if that resolves it, turn them on one at a time to see which one is interfering.

I suspect if your run your script on a different setup you will see it will run without issue.

Off Topic:

Hope you have a good Thanksgiving as well. Right now we will likely be staying home as our daughter (2 years old) and my wife both have a stomach bug and we’d hate to pass that around, but if they are feeling any better by tomorrow afternoon we may make our way to see family on Friday.

Thanks again!