Does the global inclusion of a config.php increase memory consumption?

Source: Internet
Author: User
Tags server memory
Because in addition to PHP7, the remaining versions do not support define an array, if a site global configuration of the array file, such as database account password, page number, routing rules easy to save into an array file, put into the config.php, the global use of this file is included, only need to use the $ Config, will this increase server memory consumption?

Reply content:

Because in addition to PHP7, the remaining versions do not support define an array, if a site global configuration of the array file, such as database account password, page number, routing rules easy to save into an array file, put into the config.php, the global use of this file is included, only need to use the $ Config, will this increase server memory consumption?

Theoretically, this is equivalent to Requrie ' config.php ', but consumption can be negligible.

Can ignore ...

First you should be clear that whether you define a constant array or an ordinary array, it is memory-intensive.

If you don't want to be modified after the definition, use a constant array:


  
   

如果你在定义后需要修改,那就用普通数组,比如在需要时才生成数据库连接对象:

  'db_conn_obj');function we_db(&$app) { $app['db'] = @new mysqli('127.0.0.1', 'root', 'pass', 'mysql'); register_shutdown_function(function() use ($app) { $app['db']->close(); });}function we_foo1() { global $app; if(!is_object($app['db'])) we_db($app); return $app['db']->query('select user,host from user where user = \'root\'')->fetch_all();}function we_foo2() { global $app; if(!is_object($app['db'])) we_db($app); return $app['db']->query('select user,host from user')->fetch_all();}print_r(we_foo1());print_r(we_foo2());

Since there are more things, the memory consumption will inevitably increase. But unless you configure the item to be perverted, you can generally ignore the

//from php5.6 after const can define an array, and define () began to support const FOO after php7.0 = [ [Efine];d (' FOO ');  
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.