4

I'm running into a strange issue when uploading large files via PHP (through Drupal, though that's not the issue).

Basically, my file uploads fail due to post_max_size limits being reached, even though the local directive is set to 96M, and the file is 25M.

I've ensured everything else is correct, including max_input_time, max_upload_filesize, and the IIS FastCGI idle time. All these are plenty large and not the issue.

I am overriding the post_max_size directive through Plesk, which (I believe) stores the change in a registry value. Running phpinfo() on the domain shows the correct local and master values for all directives...96M local, 12M master.

The very strange thing is that when I change the master post_max_size in php.ini from 12M to 96M (and ensure the change has taken effect), it works normally! Changing the master value back to 12M (and keeping a local value of 96M) immediately causes uploads to fail again.

Is this a bug in PHP, or am I doing it wrong?

Nick Daugherty
  • 2,763
  • 4
  • 20
  • 17

3 Answers3

2

As it turns out, on Windows, you can only set ini directives that are marked PHP_INI_USER per directory. Unfortunately, upload_max_filesize and post_max_size are both PHP_INI_PERDIR. From the PHP docs at http://php.net/manual/en/configuration.changes.php

The settings for the directory would be active for any script running from this directory or any subdirectory of it. The values under the key should have the name of the PHP configuration directive and the string value. PHP constants in the values are not parsed. However, only configuration values changeable in PHP_INI_USER can be set this way, PHP_INI_PERDIR values can not.

So even though Plesk has an interface to change those directives, and even though phpinfo() picks up on them, they do nothing to change the actual max upload sizes. Plesk should not allow you to change those on Windows, and phpinfo() should not report the change, but what can you do.

Nick Daugherty
  • 2,763
  • 4
  • 20
  • 17
1

Check PHP's post_max_size and upload_max_filesize in php.ini and for any overrides (local php.ini or .htaccess for example)

EDIT: it should be noted that phpinfo() cannot be relied upon for determining if any override will be available during the request (aka when file uploads happen) since it will be processed during the response.

Jared Kipe
  • 1,189
  • 6
  • 5
  • `post_max_size` and `upload_max_size` are both overridden (via registry, the only way to do it on Windows) to `96M`, and phpinfo() reflects that fact. – Nick Daugherty Jul 30 '12 at 22:24
  • How are you overriding them then? Keep in mind that you can't override them using ini_set() in a script that is responding to the HTTP request (because they won't be overridden until it is too late). – Jared Kipe Jul 30 '12 at 22:30
  • They are being overridden by a registry key. I'm using the Plesk control panel, which has a GUI to change PHP settings per domain, and behind the scenes it writes them to the registry, as that's really the only way to set per domain directives on Windows. `ini_set()` is not used. – Nick Daugherty Jul 30 '12 at 22:42
  • Might be simple, but have you tried restarting services, or simply rebooting with them set to override? – Jared Kipe Jul 30 '12 at 22:55
  • I haven't restarted the IIS service since this is a busy server, but I've restarted the site's app pool to no avail. Since phpinfo() reports the correct value, I know PHP is picking up on my override...it seems like PHP has a bug in it's upload mechanism that doesn't correctly consult the overridden value when actually receiving a file. – Nick Daugherty Jul 31 '12 at 15:24
  • 1
    I personally would suspect that the value is set by, whatever mechanism, after it is too late to matter. Namely during the response. But alas I don't have any real IIS experience, only nginx and apache. – Jared Kipe Aug 01 '12 at 04:56
  • I do think you are right. I'll submit an answer detailing what I found. – Nick Daugherty Aug 01 '12 at 15:28
  • Yeah, you should totally make your own answer and accept it, giving no credit to anyone else. :( – Jared Kipe Aug 01 '12 at 22:37
  • Jared, your answer did not sufficiently explain the issue, so I felt a more in depth reply was needed for future searchers. Sorry, wasn't trying to steal any credit, just want the best explanation possible. I see you edited your answer to add more info, but that was after I had already written mine. – Nick Daugherty Aug 02 '12 at 03:37
0

I had similar issues in Plesk. Have you edited any of the templates in Plesk? I know when it runs its cron jobs you can lose certain config edits if you didn't do them via Plesk.

But what about your .htaccess file? You can also set these limits there and that, based on your Plesk config, may the better place to make these changes.

roberthernandez
  • 524
  • 3
  • 10
  • Have learned the hard way to never change anything outside Plesk! As far as I know, Plesk on Windows with IIS doesn't use .htaccess files, you can only change settings in web.config and the registry, through the Plesk GUI. – Nick Daugherty Jul 31 '12 at 17:10
  • Ah, right IIS. What about the max_file_uploads? If your upload_max_filesize * max_file_uploads is greater than you memory_limit or post_max_size that could be a problem. Other directives of interest I'd imagine are memory_limit, max_execution_time, max_input_time, upload_max_filesize, max_file_uploads. – roberthernandez Jul 31 '12 at 17:19
  • All those related directives are set sufficiently high, I've even modified IIS settings such as FastCGI idle timeout, max request size, etc. Both `post_max_size` and `max_upload_filesize` are set at `96M`, but I'm only uploading 1 `25M` file. It uploads fine when setting the global php.ini directives to `96M`, and fails when you revert them to `12M`. – Nick Daugherty Jul 31 '12 at 17:28