Forum Moderators: coopster

Message Too Old, No Replies

File Upload - prevent timeout

I cannot upload files

         

swedee

6:56 pm on Sep 23, 2003 (gmt 0)

10+ Year Member



Hi

I have a problem regarding uploading files. If i have a form on page1.html with a form containing one file-field.

When I click submit the file immediately starts uploading to the temp directory on the server. If this takes longer than 30 seconds it will not work. Since that is the standard time set in PHP... I know you can change this with a simple string of code. But! There is no time for that. Exactly when I click Submit the 30 seconds starts counting... I think....

I cannot edit my php.ini

Can anyone help with this.

coopster

7:23 pm on Sep 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What server are you running?

swedee

7:28 pm on Sep 23, 2003 (gmt 0)

10+ Year Member



Hi

This is what is said under system when I run the phpinfo function.

Windows NT localhost 5.0 build 2195

/Johan

coopster

7:45 pm on Sep 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have you tried uploading a small file, like a one word text file to make sure the upload is working correctly? Also, can you give the exact error message you are receiving?

coopster

7:59 pm on Sep 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If your max_execution_time directive is set to 30, and you are able to upload the simple text file as described earlier, try adding a set_time_limit() [us3.php.net] in your script.

swedee

8:20 pm on Sep 23, 2003 (gmt 0)

10+ Year Member



The whole script works fine.. A small file works great.

The problem is that I cannot add the extra time in that set_time_limit. Cause the when someone click submit in the form-page the files start uploading immediately without running any scripts. So if I add the set_time_limit in the beginning that will execute after the files... I don't know maybe have the wrong basic concept to start with.

As far as I know it works like this. When I click the submit button PHP automatically upload the files to the temp-directory without involving any PHP-scripts. Therefore I cannot use the set_time_limit (I think). Cause the page uploads the files before anything else is executed. Am I right?

/Johan

coopster

9:17 pm on Sep 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Which web server are you running on the
Windows NT localhost 5.0 build 2195
? Apache? Internet Information Server (IIS)? Other?

Also, which version of PHP?

coopster

10:25 pm on Sep 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm not entirely sure about what happens first, file upload or script execution. The best I can find is from RFC1867 [ietf.org]: "Once the file is uploaded, it is up to the receiver to process and store the file appropriately." So I would tend to agree with you that the file upload occurs first, prior to any script processing. I also found this regarding the max_execution_time directive in the File Uploads Common Pitfalls [us2.php.net]:
Note: max_execution_time only affects the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), the sleep() function, database queries, time taken by the file upload process, etc. is not included when determining the maximum time that the script has been running.

<coopster side note here>:
If it was the script timing out, however, the max_execution_time directive also has a configuration option of PHP_INI_ALL. That means, you could create a per-directory configuration override on that value. On an apache server, this means placing an .htaccess file in that directory with a setting such as:
max_execution_time=300
which would change your script running time from 30 seconds to 5 minutes.

Therefore, assuming the script is never being executed, it would appear to be a server setting that is prohibiting you from uploading larger documents (now, the question is whether it is time or file size creating the problem). Apache has a configuration directive called LimitRequestBody [httpd.apache.org] that would make file size an issue. As far as Windows IIS goes, I found this in the user comments on the PHP: Handling file uploads manual [us2.php.net]:

This took me a few days to find out: when uploading large files with a slow connection to my WIN2K/IIS5/PHP4 server the POST form kept timing out at exactly 5 minutes. All PHP.INI settings were large enough to accomodate huge file uploads. Searched like crazy with keywords like "file upload php timeout script" until I realised that I installed PHP as CGI and added that as a keyword. This was the solution:

To set the timeout value:
1. In the Internet Information Services snap-in, select the computer icon and open its property sheets.
2. Under Master Properties, select WWW Service, and then click the Edit button
3. Click the Home Directory tab.
4. Click the Configuration button.
5. Click the Process Options tab, and then type the timeout period in the CGI Script Timeout box.

Let us know

  1. What web server you are running
  2. What version of php
  3. The exact error message you are receiving
We'll have to go from there...

swedee

10:37 pm on Sep 23, 2003 (gmt 0)

10+ Year Member



Hi thanks a lot for your efforts. Tomorrow I will get the information and post it here... I hope it helps... Thanks lot.

/Johan

swedee

4:17 pm on Sep 24, 2003 (gmt 0)

10+ Year Member



PHP Version 4.3.1
Apacheserver...

This is the error message and that is when the set_time_limit function is on the first row.

Fatal error: Maximum execution time of 30 seconds exceeded in d:\www-kunder\pixibit.com\temp_php\contributors\contributors_upload_submit.php on line 1

[edited by: jatar_k at 4:44 pm (utc) on Sep. 24, 2003]

[edited by: coopster at 3:56 pm (utc) on Oct. 5, 2005]
[edit reason] removed url [/edit]

coopster

4:32 pm on Sep 24, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



OK, it's your
max_execution_time
. See the coopster side note in post number 8 and try it to see if it will work for you; oh wait, you are running Microsoft-IIS/5.0 on Windows 2000 and I'm not sure how/if you can set a per-directory configuration in that environment. Anybody else have a clue?

swedee

5:00 pm on Sep 24, 2003 (gmt 0)

10+ Year Member



thanks a lot for your help. I think we are at the right track now...

Thanks

coopster

5:02 pm on Sep 24, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



A search on microsoft's support site on "htaccess" will turn up a few documents that may provide direction. It seems as though you can use .htaccess files with IIS [support.microsoft.com].

swedee

5:20 pm on Sep 24, 2003 (gmt 0)

10+ Year Member



Ok thanks a lot. I will try it out