duan02143 2014-02-02 15:42
浏览 51
已采纳

jQuery Ajax - >如何避免包含一个查询的每个类

I have several classes in PHP. All separated in files. (class1.php, class2.php)

On my site, I have included them all together, so I can use all of them.

Now, when I use jQuery Ajax to get data from the database I have to call another file (like getData.php)

But on this file, I have to include all of the classes (or at least some) again. So every time I want to receive data from the database, it loads all classes again(I think). The problem is, that they're not that small and they are still growing. That's bad, I think.

Is there a way to avoid this? So that I include the classes only once.

  • 写回答

1条回答 默认 最新

  • duan1930 2014-02-02 16:59
    关注

    step one: only include the files you need. How? using an autoloader (and a system that can easily determine what file contains which class, like Classname.class.php or something) will help: If you call new yourClass() the autoloader will load the file, but only that file.

    Now you have a minimal set of files loaded. This set will not get smaller, as you are actually using the files. What you can do is speed stuff up by

    1. using APC. Your PHP files get 'cached' and they don't need to be re-parsed again and again.
    2. use other forms of cache, like memcached: save certain data in memory so you don't need anything other then your memcache-class loaded (heck, you won't even hit your database anymore for these requests :) )
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?