Codeigniter。自动加载模型,会更慢吗? [英] Codeigniter. Autoload models, will things get slower?

查看:219
本文介绍了Codeigniter。自动加载模型,会更慢吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Codeigniter建立一个API。
在这个API我有10个模型,我现在使用,然后。

I am building an API using Codeigniter. In this API I got 10 models that I use now and then.

目前我正在加载它们,当我需要它们,但我正在考虑自动加载
所有模型(减少我的控制器中的空间)。

Currently I am loading them when I need them but I am thinking of auto loading all models instead (to cut down on space in my controllers).

这样做会让我失去什么?

What will I loose by doing this? Will they cause things to slow down?

推荐答案

您指示CI自动将您的模型加载到内存中,这将增加内存占用。我认为自动加载将不会有很大的性能影响,如果你有足够的RAM可用,但如果你使用 mod_php 运行PHP,那么它可能会导致一些减速,因为php进程必须重生每个请求。

You are instructing CI to auto load your models into memory, which will increase memory footprint. I think autoloading won't have much effect of performance if you have plenty of RAM available but if you run PHP using mod_php then it might cause some slowdown because php processes have to respawned per request.

无论如何,在作出决定之前 - 为您的应用程式设定档!有两种方法做到这一点。

In any case, before making a decision -- Profile your app! there are two ways to do it.


  1. PECL APD

Xdebug + kcachegrind(linux)或wincachegrind(windows),它会给你一些漂亮的图表,详细说明确切的时间,计数和内存使用情况(但你需要另一个扩展)。

Xdebug + kcachegrind (linux) or wincachegrind (windows) and it'll show you a few pretty charts that detail the exact timings, counts and memory usage (but you need another extension for that).

我建议 PECL APD 扩展程序,因为它更容易设置

I would suggest PECL APD extension because its easier to setup

这篇关于Codeigniter。自动加载模型,会更慢吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆