Forum Moderators: coopster
I've run into a very odd situation where having APC installed and running caused PHP to always choose the same tmp_name for file uploads.
Here's the settings I'm using:
extension=apc.so
apc.enabled=0
apc.shm_segments=1
apc.shm_size=256
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.stat=1
Any ideas are welcome. APC is much needed on this server, but the file upload problem is a deal killer.
If you know when/where/how php chooses the tmp_name value, that might also help me sort this out. :)
/var/tmp/phpGs5taU
I could move the file once it's done to a new random file name, but I'm still concerned about concurrent uploads (which this site actually gets).
Added: Some additional details. :) Right now my code does a non-trivial amount of validation and processing on that temporary file before moving it to it's final location (if the result of the processing is successful). So it assumes that the provided tmp_name is going to be unique. The reason this was discovered is because when multiple people in-house were using the system at the same time, they would occasionally see someone else's file in the finished result instead of seeing their own.
[edited by: whoisgregg at 10:20 pm (utc) on Sep. 11, 2009]
I setup a test page to generate the output of rand() and mt_rand() to see if the values would stay the same on refreshes. Each time I refreshed they would change. So no worries there.
However, then I made this script:
<?php echo tempnam("/var/tmp", "php"); ?>
Each time I refresh that page the output changes. However, if I upload a file then immediately refresh that page, the output of tempnam() is the *exact same* as the tmp_name of the file which was just uploaded! However, refreshing that page then causes the next uploaded file to have a new name instead of the same old name.
So APC seems to be caching the output/seed of the the tempnam script but only when it's called during a file upload. My current workaround is to call tempnam() in my upload script to force the value to change.
1. Upload file #1, logged tmp_name => /var/tmp/phppukmKe
2. Upload file #2, logged tmp_name => /var/tmp/phppukmKe
3. Refresh tempnam() script, output => /var/tmp/phppukmKe
4. Refresh tempnam() script, output => /var/tmp/phprukmKe
5. Upload file #1, logged tmp_name => /var/tmp/php99B66G
6. Upload file #2, logged tmp_name => /var/tmp/php99B66G
7. Refresh tempnam() script, output => /var/tmp/php99B66G
8. Refresh tempnam() script, output => /var/tmp/phpxukmKe
So, basically my workaround is just to call tempnam() in my upload script to force a new name to be generated, then delete that file, then handle the file upload like normal.
So I couldn't offer more help, Gregg.
Thanks for your help, it was good to have someone to bounce stuff off of. I'll definitely post back if I come up with an explanation. :)