优化Zend框架路线 [英] Optimizing Zend framework routes

查看:91
本文介绍了优化Zend框架路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用使用Zend tool生成的传统Zend框架应用程序.我的应用程序中也有几个模块,它们也都是使用Zend tool生成的.我打算在我的应用程序中使用Zend框架中的default routes.

例如:www.host.com/module/controller/action/param1/value1/param2/value2

这是我的问题:

  1. 明智的做法是,使用默认路由是最快的解决方案,对吧?
  2. 由于我永远不会更改路线,因此有没有一种方法可以使 路由过程更快?例如缓存?跳过路由 完全处理吗?或其他任何技术?
  3. 进行自定义路线的优点是什么? SEO更好吗?
  4. 我可以跳过AJAX呼叫的路由过程吗? (我知道答案 基本上没有,但也许我可以进一步优化AJAX通话的功能)

注意:

我了解路由过程本身及其在Zend中的工作方式 框架.但是,由于我不会使用大多数功能 可用,我想可能是时候进行微调了:)

谢谢.

解决方案

1.在性能方面,使用默认路由是最快的解决方案,对吧?

正确(但显然不使用任何路由系统)是最快的解决方案.

2.由于我永远都不会更改路由,有没有办法使路由过程更快?例如缓存?跳过路由 完全处理吗?或其他任何技术?

就是这样,路线主要用于灵活性,国际化,SEO.

Zend Framework Router的问题在于它依赖并包装Front Controller实例,因此,由于FC本身包装了其他不可缓存的东西(例如PDO实例),因此很难(非常不可能)缓存路由器. /p>

因此,针对每个请求一次又一次地计算所有路由.

在使用复杂路由而避免路由计算时,一种可行的解决方案是将所有路由转储到本地Apache Rewrite Rules,与ZF相比,它的速度非常快,该解决方案的主要问题是您需要手动计算反向路由,每当您更改路线时,都需要手动进行编辑.

通常是可扩展性与性能.

3.进行自定义路线的优点是什么? SEO更好吗?

好吧,它取决于"(tm):

/list?type=products/products,第二条路线获胜.

但是,/products/page/1/products?page=1是双赢的(虽然实际上不是,但这是另外一回事了.)

其他优点:

  • i18n
  • seo
  • 可用性
  • 有意义的网址

4.我可以跳过AJAX呼叫的路由过程吗? (我知道答案大多是否,但是也许我可以针对AJAX调用进一步优化自己的调用)

我对此没有任何反对意见.除了RESTfull API之外,我经常这样做.

I'm using a traditional Zend framework application generated using Zend tool. I have several modules in my application all generated using Zend tool too. I'm intending to use the default routes in Zend framework in my application.

For example: www.host.com/module/controller/action/param1/value1/param2/value2

Here are my questions:

  1. Performance wise, using the default routes is the fastest solution, right?
  2. Since I won't ever change the routes, is there a way to make the routing process even faster? caching for example? skipping the routing process entirely? or any other technique?
  3. What is the pros of making custom routes? is it better for SEO?
  4. Can I skip the routing process for AJAX calls? (I know the answer is mostly NO, but maybe I can optimize my call further for AJAX calls)

Note:

I understand the routing process itself and how it works in Zend framework. However, since I won't be using most of the features available I thought maybe it's time for fine tuning :)

Thanks in advance.

解决方案

1 . Performance wise, using the default routes is the fastest solution, right?

Right, but not using any routing system is the fastest solution (obviously).

2 . Since I won't ever change the routes, is there a way to make the routing process even faster? caching for example? skipping the routing process entirely? or any other technique?

Well, that's the thing, routes are mostly used for flexibility, internationalization, SEO.

The problem with the Zend Framework Router is that it depends and wraps the Front Controller instance, therefore it is hard (well impossible afaik) to cache the Router since the FC itself wraps others things like PDO instances which are not cachable.

So all routes are computed again and again for every requests.

A possible solution when using complex routes while avoiding route computation is to dump all routes to native Apache Rewrite Rules, it will be blazing fast compared to ZF, the main problem with this solution is that you need to manually compute reverse routes and whenever you make a change to a route, you'll need to edit it by hand.

As often, it is scalability vs performance.

3 . What is the pros of making custom routes? is it better for SEO?

Well, it "depends" (tm):

/list?type=products vs /products, the second route wins.

However, /products/page/1 vs /products?page=1 is a win-win (well it actually does not but it is another story).

Other pros:

  • i18n
  • seo
  • usability
  • meaningful url

4 . Can I skip the routing process for AJAX calls? (I know the answer is mostly NO, but maybe I can optimize my call further for AJAX calls)

I don't see any cons against this. I often go for it, except for RESTfull API.

这篇关于优化Zend框架路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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