XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/include/memory_limit.php @ 860

Last change on this file since 860 was 860, checked in by toemon, 8 years ago

PHP7 対応 Fix #431
thx nao-pon

File size: 2.0 KB
Line 
1<?php
2        // Set XPressME memory limit
3        function xpress_set_memory_limmit(){
4                global $xoops_config;
5                global $xoopsDB;
6               
7                $module_id = '';
8                $memory = '';
9               
10                if (!is_object($xoops_config)){
11                        require_once dirname(dirname( __FILE__ )).'/class/config_from_xoops.class.php' ;
12                        $xoops_config = new ConfigFromXoops;
13                }
14               
15                $has_xoops_db = (!empty($xoopsDB));
16                if (!$has_xoops_db) {
17                        $cn = mysqli_connect($xoops_config->xoops_db_host, $xoops_config->xoops_db_user, $xoops_config->xoops_db_pass);
18                        if ($cn){
19                                $db_selected = mysqli_select_db($cn, $xoops_config->xoops_db_name);
20                        }
21                }
22
23                // get module ID
24                $module_table = $xoops_config->xoops_db_prefix . '_modules';
25                $module_sql = "SELECT mid FROM $module_table WHERE `dirname` = '$xoops_config->module_name'";
26                if ($has_xoops_db) {
27                        if ($result = $xoopsDB->query($module_sql, 0, 0)){
28                                $row = $xoopsDB->fetchArray($result);
29                                $module_id = $row['mid'];
30                        }       
31                } else {
32                        if ($db_selected){
33                                if($result = mysqli_query($cn, $module_sql)){
34                                        $row = mysqli_fetch_assoc($result);
35                                        $module_id = $row['mid'];
36                                }
37                        }
38                }
39                if (!empty($module_id)){
40                        // get memory_limit
41                        $config_table = $xoops_config->xoops_db_prefix . '_config';
42                        $config_sql = "SELECT conf_value FROM $config_table WHERE `conf_modid` = $module_id AND `conf_name` = 'memory_limit'";
43                        if ($has_xoops_db) {
44                                if ($result = $xoopsDB->query($config_sql, 0, 0)){
45                                        $row = $xoopsDB->fetchArray($result);
46                                        $memory = $row['conf_value'];
47                                }
48                        } else {
49                                if ($db_selected){
50                                        if($result = mysqli_query($cn, $config_sql)){
51                                                $row = mysqli_fetch_assoc($result);
52                                                $memory = $row['conf_value'];
53                                        }
54                                }
55                        }
56                }
57                if (!$has_xoops_db) {
58                        mysqli_close($cn);
59                }
60               
61                if (empty($memory)) return;
62                if ( !defined('WP_MEMORY_LIMIT') )
63                        define('WP_MEMORY_LIMIT', $memory . 'M');
64                if ( function_exists('memory_get_usage') && ( (int) @ini_get('memory_limit') < abs(intval(WP_MEMORY_LIMIT)) ) )
65                        @ini_set('memory_limit', WP_MEMORY_LIMIT);
66        }
67?>
Note: See TracBrowser for help on using the repository browser.