How to set higher memory_limit, post_max_size and for a specific script in Apache / PHP?

I have a web application that redirects all requests to a virtual host to a controller, and then decides which files to include and run based on the URL. There is a web service that accepts large XML files through POST. I need memory_limit and post_max_ to be ~ 32M for the application, with the exception of a service that accepts XML, which would require their limits to be closer to 1024M. ini_set('memory_limit','1024M')works in a script but will not work for post_max_size.

I can’t figure out how to do this. I tried something like this:

<VirtualHost *:80>
ServerName test.com
DocumentRoot /var/www/test.com/html


php_admin_value include_path .:/var/www/test.com/includes:/var/www/test.com/includes/libs

php_value session.use_only_cookie 1
<Location />
    php_value memory_limit 32M
    php_value post_max_size 30M
    php_value upload_max_filesize 29M
</Location>
<Location /services/big-service>
    php_value memory_limit 1024M
    php_value post_max_size 128M
</Location>

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteCond %{REQUEST_URI} !^/(.*)(html|gif|jpg|png|ico|css|js|dtd|swf|flv|xml)$
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/(.*)$ /Controller.php/$1 [PT]

</VirtualHost>

So with the above configuration, if Controller.php looks like

<?php
echo '<pre>';
var_dump(ini_get('memory_limit'));
var_dump(ini_get('post_max_size'));
var_dump(ini_get('upload_max_filesize'));

I will get line (3) "32M" line (3) "30M" line (3) "29M"

http://test.com http://test.com/services/big-service, URL-.

- - , script URL?

+5
5

, mod_rewrite , /Controller.php, . mod_rewrite

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/services/(.*)$
RewriteCond %{REQUEST_URI} !^/(.*)(html|gif|jpg|png|ico|css|js|dtd|swf|flv|xml)$
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/(.*)$ /ControllerBig.php/services/$1 [PT]

, ControllerBig, Controller

<?php
require_once('Controller.php');

.

: VirtualHost:

<VirtualHost *:80>
ServerName test.com
DocumentRoot /var/www/test.com/html

php_admin_value include_path .:/var/www/test.com/includes:/var/www/test.com/includes/libs

php_value session.use_only_cookie 1
<Location />
    php_value memory_limit 32M
    php_value post_max_size 30M
    php_value upload_max_filesize 29M
</Location>
<Location /services/big-service>
    php_value memory_limit 1024M
    php_value post_max_size 128M
</Location>

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/services/(.*)$
RewriteCond %{REQUEST_URI} !^/(.*)(html|gif|jpg|png|ico|css|js|dtd|swf|flv|xml)$
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/(.*)$ /ControllerBig.php/services/$1 [PT]

RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteCond %{REQUEST_URI} !^/(.*)(html|gif|jpg|png|ico|css|js|dtd|swf|flv|xml)$
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/(.*)$ /Controller.php/$1 [PT]

</VirtualHost>
+1

, - , , . php.ini, , PHP script, .ini, .

php.ini, ini_set() , . , , , post_max_size , script.

, PHP script post_max_size php.ini, , , , script .

0

AFAIK php.ini - php (php5_module), .

  • php5_module - , - Apache. , 80

  • FCGI php php5_module. . - .php fcgi (,.fcgi)

LoadModule fcgid_module modules/mod_fcgid.so  

LoadModule php5_module c:/apps/php/php5apache2_2.dll
AddHandler application/x-httpd-php .php
PHPIniDir "C:/apps/php/ini1"

<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi 
FcgidInitialEnv PHPRC "c:/apps/php/ini2"
FcgidWrapper "c:/apps/php/php-cgi.exe" .fcgi
AddType    application/x-httpd-fcgi .fcgi
</IfModule>

, ,

0

( DNS), , .

, URL- /services/big -service DNS ( , URL-.

php_value VirtualHost, . , , memory_limit PERDIR, , VirtualHost, PERDIR a <Directory>, , <Location> ( mod_rewrite index.php, Directory).

2- DNS- , apache, 1024 , , . - (, MaxRequestPerChild 100).

Fcgid php-fpm, mod_php PHP script , ( , , 10 %/30%/50% php RAM - ). Zend_Memory, Zend_Cache, " swapp ", , .

0

I doubt it will work. Since the redirect always goes to Controller.php, and I don't think Apache will support a different php.ini value based on Location.

If / services / big-service is a directory, then it makes sense to accept values ​​for PHP, I would suggest you have a common php.ini value or create a directory and write .htaccess to have its own php settings.

0
source

All Articles