hadenp Posted August 7, 2010 Share Posted August 7, 2010 When I upload files > 2MB, I get an "Internal Server Error" and in the errors log see "Premature end of script headers:..." No problem with smaller files. I'm running PHP 5.28 and have the following in php5.ini. magic_quotes_gpc = Off log_errors = on display_errors = off memory_limit = 64M post_max_size = 8M upload_max_filesize = 8M max_input_time = 360 max_execution_time = 360 upload_tmp_dir = amd_temp The permissions for the upload folder are set to 755. Here's the code: <?php if ($_SERVER['REQUEST_METHOD'] == 'GET') { ?> <form method="post" action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" enctype="multipart/form-data"> <input type="file" name="document"/> <input type="submit" value="Send File"/> </form> <?php } else { if (isset($_FILES['document']) && ($_FILES['document']['error'] == UPLOAD_ERR_OK)) { $newPath = 'updocs/' . basename($_FILES['document']['name']); if (move_uploaded_file($_FILES['document']['tmp_name'], $newPath)) { print "File saved in $newPath"; } else { print "Couldn't move file to $newPath"; } } else { print "No valid file uploaded."; } } ?> Any thoughts on what might be the problem? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/ Share on other sites More sharing options...
RussellReal Posted August 8, 2010 Share Posted August 8, 2010 Some apache configurations limit the post size and file sizes also, aswell as enforce a timeout for the connection.. That is number one.. use set_time_limit and set the time limit to 0(unlimited).. for the first one.. you probably don't have to worry, but you can talk to your hosting provider to update your configuration for you and the second one you already handle in your php ini but it shouldn't hurt to try it all in all I don't see why there would be a problem Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/#findComment-1096462 Share on other sites More sharing options...
hadenp Posted August 9, 2010 Author Share Posted August 9, 2010 I contacted my hosting provider (GoDaddy) and to my surprise their upload limit is 8MB! (overridable) - the same as my limit - so file size can't be the issue. Even though I'd never had a problem uploading small files, I tried my script on a different server and uploaded a 6MB file. (I got a permissions error at first - so I chmoded the upload directory to allow write access - 777.) After chmoding the target directory on the GoDaddy site, I tried again but still no success uploading files over 1 MB. So this is a real conundrum. (The set_time_limit(0) didn't help - but thanks for the suggestion.) Is there some other permissions issue I'm not aware of? How do I find out the permissions my PHP program has? Is there a way to get a more specific error message than the 'Internal Server Error' & 'Premature end of script headers' - supplied by Apache I believe. Thanks in advance for you suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/#findComment-1096828 Share on other sites More sharing options...
jcbones Posted August 9, 2010 Share Posted August 9, 2010 Run a test file with this inside. <?php phpinfo(); ?> Look under CORE and examine these lines. file_uploads = ON/OFF max_execution_time = maximum amount of time the script will run. memory_limit = maximum amount of memory the script can allocate. post_max_size = maximum size for POST. upload_max_filesize = maximum size for a file upload. Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/#findComment-1096837 Share on other sites More sharing options...
hadenp Posted August 9, 2010 Author Share Posted August 9, 2010 Yes, I've been using phpinfo.php to verify these values ...but I checked them again. All the values are as listed in my original post - except for 'upload_files = on' - (didn't list that in op) and 'post_max_size = 10M'). Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/#findComment-1096856 Share on other sites More sharing options...
jcbones Posted August 9, 2010 Share Posted August 9, 2010 The errors 'Internal Server Error' & 'Premature end of script headers', are indeed apache. The specifics should be in the server error log. What is your current time limit set at? I don't see it in your list. Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/#findComment-1097183 Share on other sites More sharing options...
hadenp Posted August 10, 2010 Author Share Posted August 10, 2010 Thanks for your reply. I see the 'Internal Server Error' on the screen and the 'Premature end of script headers:' + path/program_name in the errors log. I use GoDaddy's 'Error Log' interface to view the errors. Something more specific would likely help shed light on what's causing the error - but it isn't there. For time limits, I've set these in php5.ini: max_input_time = 360 max_execution_time = 360 When there's an error, it returns in ~1 minute, so I don't think time is the issue. I'm thinking it must be a permissions issue - but why it only appears with larger files (and only on GoDaddy) is for me, the paradox. On the GoDaddy site, PHP is run as a cgi but on the server where I tested successfully it runs as an apache module. I don't think that should matter, but I don't know... Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/#findComment-1097347 Share on other sites More sharing options...
gizmola Posted August 10, 2010 Share Posted August 10, 2010 When you get an internal Server Error message, something blew up in apache. It's possible that your script is running out of memory (using more than the 64mb limit) and that is why you're getting the internal server error. Bump up the memory limit and see if that fixes the problem. You can also help diagnose this using the memory_get_usage() function at various places in your script to see what's happening. Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/#findComment-1097353 Share on other sites More sharing options...
hadenp Posted August 14, 2010 Author Share Posted August 14, 2010 Today I got GoDaddy tech support to replicate the error. Their explanation was that the script stops (or is terminated?) due to a setting in the shared hosting environment and that moving to a virtual dedicated server 'might' correct it. Not sure if that makes sense since it seems that this is a resource issue - but I don't know much about shared hosting vs VPS. At that point (I'd been on the phone with them for over an hour) I didn't remember this article - http://help.godaddy.com/article/1475? which to me contradicts what I was told. Oh well, guess I'll call them back. BTW, I did try bumping up the memory and get_memory_usage function(true) ...but without success. Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/#findComment-1099092 Share on other sites More sharing options...
gizmola Posted September 13, 2010 Share Posted September 13, 2010 Just to close this out... yeah in shared hosting you can't change settings like memory_limit, nor can you restart apache. I have no doubt it was a memory issue. Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/#findComment-1110498 Share on other sites More sharing options...
RussellReal Posted September 13, 2010 Share Posted September 13, 2010 Today I got GoDaddy tech support to replicate the error. Their explanation was that the script stops (or is terminated?) due to a setting in the shared hosting environment and that moving to a virtual dedicated server 'might' correct it. Not sure if that makes sense since it seems that this is a resource issue - but I don't know much about shared hosting vs VPS. At that point (I'd been on the phone with them for over an hour) I didn't remember this article - http://help.godaddy.com/article/1475? which to me contradicts what I was told. Oh well, guess I'll call them back. BTW, I did try bumping up the memory and get_memory_usage function(true) ...but without success. if you're going to move to a VPS there are alot better VPS servers out there for less money than godaddy charges, I currently use WestHost (no this isn't a solicitation, no referral links here , just a friendly suggestion!) - Russell Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/#findComment-1110614 Share on other sites More sharing options...
hadenp Posted September 13, 2010 Author Share Posted September 13, 2010 According to the tech support people, the reason larger uploads (> 2MB) would fail was due to either a timeout on how long the script was allowed to run or as pointed out, a memory limitation. So would moving to a VPS very likely fix this type of error? The reason I ask this is because, if I understand correctly, with a VPS one still shares the cpu and memory w/ an unknown # of other applications and therefore my app is contending for resources. My guess is that even with "busy" neighbors my uploads that were in effect being yanked would still proceed, but just take longer... correct? Thanks for responding! Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/#findComment-1110648 Share on other sites More sharing options...
RussellReal Posted September 19, 2010 Share Posted September 19, 2010 According to the tech support people, the reason larger uploads (> 2MB) would fail was due to either a timeout on how long the script was allowed to run or as pointed out, a memory limitation. So would moving to a VPS very likely fix this type of error? The reason I ask this is because, if I understand correctly, with a VPS one still shares the cpu and memory w/ an unknown # of other applications and therefore my app is contending for resources. My guess is that even with "busy" neighbors my uploads that were in effect being yanked would still proceed, but just take longer... correct? Thanks for responding! the only resource which is shared on a vps is the bandwidth.. on a vps you get ram, and then you get what they call burstable ram.. ram is what your account has dedicated.. so you will never be disallowed that much ram.. burstable ram is how much ram you could be bumped up to if other people aren't using as much RAM and your applications require more.. but that is your absolute max... and there is no guarantee to ever be able to touch your burstable ram limit.. most vps also give you a certain cpu percentage which you're dedicated, not sure if they have it set up for burstable also.. the only thing that is shared is the incoming and outgoing bandwidth Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/#findComment-1112686 Share on other sites More sharing options...
gizmola Posted September 24, 2010 Share Posted September 24, 2010 According to the tech support people, the reason larger uploads (> 2MB) would fail was due to either a timeout on how long the script was allowed to run or as pointed out, a memory limitation. So would moving to a VPS very likely fix this type of error? The reason I ask this is because, if I understand correctly, with a VPS one still shares the cpu and memory w/ an unknown # of other applications and therefore my app is contending for resources. My guess is that even with "busy" neighbors my uploads that were in effect being yanked would still proceed, but just take longer... correct? Thanks for responding! the only resource which is shared on a vps is the bandwidth.. on a vps you get ram, and then you get what they call burstable ram.. ram is what your account has dedicated.. so you will never be disallowed that much ram.. burstable ram is how much ram you could be bumped up to if other people aren't using as much RAM and your applications require more.. but that is your absolute max... and there is no guarantee to ever be able to touch your burstable ram limit.. most vps also give you a certain cpu percentage which you're dedicated, not sure if they have it set up for burstable also.. the only thing that is shared is the incoming and outgoing bandwidth There are different VPS technologies. The one Russell is referring to is Virtuozzo. It has this short term "burstable" setting that can grab some memory from the server pool at times of extreme stress. One issues with Virtuozzo is that VPS's do not have any virtual memory, so when you use up all your allocated memory, things start to die. Because Virtuozzo maximizes the use of the available server resources, it's very popular with hosting companies. Xen is the basis for other companies and has more robust virtualization. You see Xen used on Amazon EC3 and with certain hosting companies. A Xen guest gets a certain amount of ram from the total amount available on the server at startup and will never get more or less than that. In either case you get a certain allocation of memory that you can depend on, and more importantly you have root on the server, and can manage it any way you see fit. When you want to change php settings, you can go in and edit the /etc/php.ini file and restart apache -- things that you can't do on a shared host. Quote Link to comment https://forums.phpfreaks.com/topic/210063-problem-uploading-larger-files/#findComment-1114869 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.