Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 单个文件夹或模块的内存限制_Php_Codeigniter_Memory Management_Hmvc_Memory Limit - Fatal编程技术网

Php 单个文件夹或模块的内存限制

Php 单个文件夹或模块的内存限制,php,codeigniter,memory-management,hmvc,memory-limit,Php,Codeigniter,Memory Management,Hmvc,Memory Limit,我正在使用带有hmvc库的codeigniter框架开发一个php应用程序,该应用程序将具有模块,我希望每个模块具有不同的内存限制。这可能吗?您可以使用内存限制配置将.htaccess添加到每个模块的根目录中: <IfModule mod_php5.c> php_value memory_limit 32M </IfModule> 即使这可能有效,我也不相信它。我喜欢你提到的方法,但让我想知道我是否能够用phpI动态修改.htaccess文件——这是一个潜在的安

我正在使用带有hmvc库的codeigniter框架开发一个php应用程序,该应用程序将具有模块,我希望每个模块具有不同的内存限制。这可能吗?

您可以使用内存限制配置将
.htaccess
添加到每个模块的根目录中:

<IfModule mod_php5.c>
    php_value memory_limit 32M
</IfModule>

即使这可能有效,我也不相信它。

我喜欢你提到的方法,但让我想知道我是否能够用phpI动态修改.htaccess文件——这是一个潜在的安全风险:虽然可能有安全的方法,但它不会是微不足道的。我试图实现的是“动态设置每个模块的内存限制”有什么线索吗?为什么要这样做?为什么不设置静态限制?有什么变化会让你想要更改限制?用户数量?每天的时间?这是可行的(不容易),但首先要弄清楚你是否真的需要它。模块将由第三方开发,它们将在我的平台上执行,我需要允许他们为模块购买额外内存,当他们这样做时,应用程序将增加他们的内存限制
private function _set_mem_limit($limit = 0, $module = '')
{
    //modules
    $available_modules = array(
        'module1' => '/var/www/myApp/modules/module1/',
        'module2' => '/var/www/myApp/modules/module2/',
    );

    //limits
    $available_limits = array(
        '32'    => '32M',
        '64'    => '64M',
        '128'   => '128M',
        '256'   => '256M',
        '512'   => '512M'
    );

    $string = 'php_value memory_limit ';

    // make sure limit is an integer and it is in the available_limits array
    // if so, set string with the selected limit from array. otherwise, exit
    if(gettype($limit) === 'integer' and in_array($limit, $available_limits))
    {
        $string .= $available_limits[$limit];
    }
    else
    {
        die('Problem setting mem limit.');
    }

    // make sure incoming module variable is only alphanumeric and exists in
    // available_modules array. if so, write the limit to the file. otherwise, exit
    if(ctype_alpha($module) and in_array($module, $available_modules))
    {
        $path = $available_modules[$module].'.htaccess';
        $f = fopen($path, 'w');
        fwrite($f, $string);
        fclose($f);

    }
    else
    {
        die('Problem setting path for mem limit.');
    }
}