[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1734
  • Last Modified:

Uploads Problem: PHP IIS7 Uploadify and Server Timeouts

Dear Experts,

I have a problem with Uploadify not uploading big files. I have tried to modify every setting that I can find to increase the size allowed. Now I have run out of things to try, and need your help!

Problem:
Uploads which take over 1 minute and fifty seconds, never actually finish uploading.

Background:
I have written my own CMS, and I have used the "Uploadify" JQuery Plugin for doing the file uploads.
Other possibly relevant information at the foot of the question.


Things I have tried:
Changing php.ini :
  to allow 100M in uploads
  to allow uploads
  to allow 100M in posts
Changing IIS:
  executionTimeout: 00:10:00
  maxRequestLength: 1024000
  executionTimeout to 00:30:00
Changed some other IIS stuff which seems relevant

Things I have noticed:
The file starts to appear in the (php-temp) Uploads folder on the server, but crucially, stop getting any bigger after exactly 00:01:50. This as it happens is the original setting for executionTimeout. So I wonder id it is related..?

Things you should know:
I have re-started IIS..!

More background:
Server: Windows 200 r2 Web Edition
Main Application: ASP (Classic)
PHP Version: 5.3.3
PHP.ini File: Yes the right one is loaded..!

Thanks for your time

G_H
(E-E Classic ASP Master)
0
G_H
Asked:
G_H
  • 8
  • 6
2 Solutions
 
Ray PaseurCommented:
Can you perform the uploads with simple POST method uploads, without using uploadify?
0
 
G_HAuthor Commented:
Hi Ray, thanks for responding.

Yes - I have used my normal file upload process (freeASPupload) which is working fine. I have uploaded a file to test it, which was 15MB, and took 02:21 to upload.

To test the theory, since posting the question, I also asked a friend to upload a file for me. He has a slower broadband connection, and managed to upload 4.5MB in 01:50 and then the PHP appeared to fail.

GH
0
 
Ray PaseurCommented:
Sounds like you may be on the threshold of an intricate debugging operation.  When you upload files via PHP's POST method, you get an array called $_FILES.  It has all the information you need.  You might try printing that out.  It may be empty if the upload failed, or it may contain an error code.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
G_HAuthor Commented:
Hi Ray,

I have taken the first steps, so I thought I had better update the thread...

I have (to avoid any confusion) taken the file-upload-form from Tizag. I have also edited the code from Uploadify.

Before you look too closely at the code, I am "ASP", I can understand PHP, if you speak very, very slowly!! (I can also write it, but only if I have the manual in my other hand...)

Code:
 
<form enctype="multipart/form-data" action="/uploadify.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000" />
Choose a file to upload: <input name="Filedata" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

Open in new window

<?php
if (!empty($_FILES)) {

	$tempFile = $_FILES['Filedata']['tmp_name'];
	echo $tempFile.'<br />';

	$targetPath = $_SERVER['DOCUMENT_ROOT'] . '\\images\\uploads\\';
	echo $targetPath.'<br />';

	$targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
	echo $targetFile.'<br />';

	move_uploaded_file($tempFile,$targetFile);
	echo 'Moved!<br />';

	echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
} else {
echo 'Sweet nothing...';
}
?>

Open in new window


This has exactly the same effect... Small to medium files upload fine, larger ones die at the 1minute 50 second mark. The behaviour is same as before:

Browser starts upload,
file appears in the templ_uploads directory, and start growing
01:50 file stops growing
eventually some time later (file size dependant) the browser thinks it is done.

Currently I have special error pages, on this Windows / Classic ASP server, so I am just getting a MS-Generated 500 page.

As a side, on Tizag it mentions that if you do nothing with the file when it has been uploaded, it will be deleted. I tested this, and it works (small file). So it may be relevant that the files which have failed are still in the temp_uploads folder, or at least 1 minute 50's worth...

I will now go and turn MS-500's off, so I can see the error messages...

BRB

GH
0
 
Ray PaseurCommented:
Empty($_FILES) is only one test.  There are upload error codes to be checked, too.  Here is a teaching example of how to upload a file or three.  Hopefully the comments will be useful.  Check the man pages about POST-method uploads and common pitfalls, too.

Getting the error messages will be helpful, but if I recall correctly no error message will show if the attempt is to upload a file that does not fit under MAX_FILE_SIZE and post_max_size and upload_max_filesize.  You can check the output of phpinfo(); to see these things.
<?php // RAY_upload_example.php
error_reporting(E_ALL);


// MANUAL REFERENCE PAGES YOU MUST UNDERSTAND TO UPLOAD FILES
// http://php.net/manual/en/features.file-upload.php
// http://php.net/manual/en/features.file-upload.common-pitfalls.php
// http://php.net/manual/en/function.move-uploaded-file.php


// PHP 5.1+  SEE http://php.net/manual/en/function.date-default-timezone-set.php
date_default_timezone_set('America/Chicago');

// ESTABLISH THE NAME OF THE 'uploads' DIRECTORY
$uploads = 'RAY_junk';

// ESTABLISH THE BIGGEST FILE SIZE WE CAN ACCEPT - ABOUT 8 MB
$max_file_size = '8192000';

// ESTABLISH THE MAXIMUM NUMBER OF FILES WE CAN UPLOAD
$nf = 3;

// ESTABLISH THE KINDS OF FILE EXTENSIONS WE CAN ACCEPT
$file_exts = array
( 'jpg'
, 'gif'
, 'png'
, 'txt'
, 'pdf'
)
;

// LIST OF THE ERRORS THAT MAY BE REPORTED IN $_FILES[]["error"] (THERE IS NO #5)
$errors = array
( 0 => "Success!"
, 1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini"
, 2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"
, 3 => "The uploaded file was only partially uploaded"
, 4 => "No file was uploaded"
, 5 => "UNDEFINED ERROR"
, 6 => "Missing a temporary folder"
, 7 => "Cannot write file to disk"
)
;




// IF THERE IS NOTHING IN $_POST, PUT UP THE FORM FOR INPUT
if (empty($_POST))
{
    ?>
    <h2>Upload <?php echo $nf; ?> file(s)</h2>

    <!--
        SOME THINGS TO NOTE ABOUT THIS FORM...
        ENCTYPE IN THE HTML <FORM> STATEMENT
        MAX_FILE_SIZE MUST PRECEDE THE FILE INPUT FIELD
        INPUT NAME= IN TYPE=FILE DETERMINES THE NAME YOU FIND IN $_FILES ARRAY
        ABSENCE OF ACTION= ATTRIBUTE IN FORM TAG CAUSES POST TO SAME SCRIPT
    -->

    <form name="UploadForm" enctype="multipart/form-data" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size; ?>" />
    <p>
    Find the file(s) you want to upload and click the "Upload" button below.
    </p>

    <?php // CREATE INPUT STATEMENTS FOR UP TO $n FILE NAMES
    for ($n = 0; $n < $nf; $n++)
    {
        echo "<input name=\"userfile$n\" type=\"file\" size=\"80\" /><br/>\n";
    }
    ?>

    <br/>Check this box <input autocomplete="off" type="checkbox" name="overwrite" /> to <strong>overwrite</strong> existing files.
    <input type="submit" value="Upload" />
    </form>
    <?php
    die();
}
// END OF THE FORM SCRIPT



// WE HAVE GOT SOMETHING IN $_POST - RUN THE ACTION SCRIPT
else
{
    // THERE IS POST DATA - PROCESS IT
    echo "<h2>Results: File Upload</h2>\n";

    // ACTIVATE THIS TO SEE WHAT IS COMING THROUGH
    //    echo "<pre>"; var_dump($_FILES); var_dump($_POST); echo "</pre>\n";

    // ITERATE OVER THE CONTENTS OF $_FILES
    foreach ($_FILES as $my_uploaded_file)
    {
        // SKIP OVER EMPTY SPOTS - NOTHING UPLOADED
        $error_code    = $my_uploaded_file["error"];
        if ($error_code == 4) continue;

        // SYNTHESIZE THE NEW FILE NAME
        $f_type    = trim(strtolower(end    (explode( '.', basename($my_uploaded_file['name'] )))));
        $f_name    = trim(strtolower(current(explode( '.', basename($my_uploaded_file['name'] )))));
        $my_new_file = getcwd() . '/' . $uploads . '/' . $f_name . '.' . $f_type;
        $my_file     =                  $uploads . '/' . $f_name . '.' . $f_type;

        // OPTIONAL TEST FOR ALLOWABLE EXTENSIONS
        if (!in_array($f_type, $file_exts)) die("Sorry, $f_type files not allowed");

        // IF THERE ARE ERRORS
        if ($error_code != 0)
        {
            $error_message = $errors[$error_code];
            die("Sorry, Upload Error Code: $error_code: $error_message");
        }

        // GET THE FILE SIZE
        $file_size = number_format($my_uploaded_file["size"]);

        // IF THE FILE IS NEW (DOES NOT EXIST)
        if (!file_exists($my_new_file))
        {
            // IF THE MOVE FUNCTION WORKED CORRECTLY
            if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
            {
                $upload_success = 1;
            }
            // IF THE MOVE FUNCTION FAILED
            else
            {
                $upload_success = -1;
            }
        }

        // IF THE FILE ALREADY EXISTS
        else
        {
            echo "<br/><b><i>$my_file</i></b> already exists.\n";

            // SHOULD WE OVERWRITE THE FILE? IF NOT
            if (empty($_POST["overwrite"]))
            {
                $upload_success = 0;
            }
            // IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
            else
            {
                $now    = date('Y-m-d');
                $my_bak = $my_new_file . '.' . $now . '.bak';
                if (!copy($my_new_file, $my_bak))
                {
                    echo "<br/><strong>Attempted Backup Failed!</strong>\n";
                }
                if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
                {
                    $upload_success = 2;
                }
                else
                {
                    $upload_success = -1;
                }
            }
        }

        // REPORT OUR SUCCESS OR FAILURE
        if ($upload_success == 2) { echo "<br/>It has been overwritten.\n"; }
        if ($upload_success == 1) { echo "<br/><strong>$my_file</strong> has been saved.\n"; }
        if ($upload_success == 0) { echo "<br/><strong>It was NOT overwritten.</strong>\n"; }
        if ($upload_success < 0)  { echo "<br/><strong>ERROR: $my_file NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND</strong>\n"; }
        if ($upload_success > 0)
        {
            echo "$file_size bytes uploaded.\n";
            if (!chmod ($my_new_file, 0755))
            {
                echo "<br/>chmod(0755) FAILED: fileperms() = ";
                echo substr(sprintf('%o', fileperms($my_new_file)), -4);
            }
            echo "<br/><a href=\"$my_file\">See the file $my_file</a>\n";
        }
    // END FOREACH ITERATOR - EACH ITERATION PROCESSES ONE FILE
    }
}

Open in new window

0
 
G_HAuthor Commented:
Hi,

I got the same result with your beautiful script as I did with the other one.

I did make 2 adjustments:
updated your size limit to approx. 32MB (My Problems are round 11 to 12 MB at my upload speed)
Updated file type to include avi (As I have a good range of file of this type in useful sizes)

I can upload 6MB fine, but 16MB still ends up with a 500.

You are right about the Errors. I cannot get anything useful out.

I have attached a screenshot of ProcMon, centered around the 01:50:00 of the upload starting. I can see the file growing until this point (as seen in the ProcMon listing) but then it stops. Even though the browser still says uploading.

STOP PRESS

I just had a brain-wave... I logged onto one of my other servers, and loaded your script from there.
(Your Script modified again to allow ZIP & SQL)
I successfully uploaded a 16MB zip and a 22MB SQL file.

This further leads me to believe it is a Script / Request time-out rather than a coding error.

I still do not know what is wring though!

GH


 Process Monitor Screen shot at "die" time
0
 
Ray PaseurCommented:
Maybe try raising the execution time.  Maybe something like set_time_limit(600) to allow ten minutes of PHP processing.
0
 
G_HAuthor Commented:
I have php.ini set as:

max_execution_time = 300
( confirmed through phpinfo() )

I added the suggested line t the start of the test script, but no dice... Still the file stops growing after 01:50

GH
0
 
Ray PaseurCommented:
Where is this hosted?  Is there a tech support department you can engage in this question?
0
 
G_HAuthor Commented:
It is on a "Hardware Support Only" Dedicated Server. In a data-centre here in the UK.

GH
0
 
Ray PaseurCommented:
Well, I'm stumped.  At this point I would normally be suggesting that you change from HTTP to FTP.  That makes sense to me for long uploads, and I think anything that takes more than a few seconds qualifies as "long."  

Suggest you delete the question and ask it again (many experts will not look at questions that already have a number of comments).  Omit the PHP and AJAX Zones - we have gotten far enough to show that those are not the problem.

Sorry I could not find the magic bullet.  But I hope someone else at EE can home in on the true issue and find you a good solution.  Best regards, ~Ray
0
 
G_HAuthor Commented:
Hi Ray, think you for the suggestion, and your help to date.

I think you are right about AJAX, but my thinking is still that this is a PHP on IIS7 issue.

I'll leave the question open for a while, and try making the target for the Upload in ASP (as I normally would). Then I could close with that. {Crosses fingers, and sets brain on motion...}

Thanks for your help to date,

GH
0
 
G_HAuthor Commented:
OK, in the last few hours, I have re-written the script which actually accepts the upload in my native tongue (Classic ASP). This is behaving exactly as it should, and obeying the time-outs etc.

I still have no idea why IIS/PHP was inforcing the 01:50 limit which I had up-ed to 10 minutes, but at least I have my "solution".

Thanks again to Ray.

GH
0
 
G_HAuthor Commented:
Solution was to take a different approach..!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now