PHP 5 Reflection API性能 [英] PHP 5 Reflection API performance

查看:65
本文介绍了PHP 5 Reflection API性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在考虑在自己的MVC Web框架中使用反射类(主要是ReflectionionClass和ReflectionMethod),因为我需要自动实例化控制器类并在没有任何必需配置的情况下调用它们的方法(约定之上的配置"方法)

I'm currently considering the use of Reflection classes (ReflectionClass and ReflectionMethod mainly) in my own MVC web framework, because I need to automatically instanciate controller classes and invoke their methods without any required configuration ("convention over configuration" approach).

我担心性能,尽管我认为数据库请求可能比实际的PHP代码更大的瓶颈.

I'm concerned about performance, even though I think that database requests are likely to be bigger bottlenecks than the actual PHP code.

因此,我想知道从性能的角度看,是否有人对PHP 5 Reflection有任何好的或坏的体验.

So, I'm wondering if anyone has any good or bad experience with PHP 5 Reflection from a performance point of view.

此外,我很想知道是否有一种流行的PHP框架(CI,Cake,Symfony等)实际上使用了反射.

Besides, I'd be curious to know if any one of the popular PHP frameworks (CI, Cake, Symfony, etc.) actually use Reflection.

推荐答案

不用担心.安装 Xdebug 并确定瓶颈在哪里.

Don't be concerned. Install Xdebug and be sure where the bottleneck is.

使用反射是有成本的,但是是否重要取决于您在做什么.如果您使用反射实现控制器/请求分派器,则每个请求仅是一种用途.绝对可以忽略不计.

There is cost to using reflection, but whether that matters depends on what you're doing. If you implement controller/request dispatcher using Reflection, then it's just one use per request. Absolutely negligible.

如果您使用反射实现ORM层,将其用于每个对象甚至对属性的每次访问,并创建成百上千个对象,那么这可能会很昂贵.

If you implement your ORM layer using reflection, use it for every object or even every access to a property, and create hundreds or thousands objects, then it might be costly.

这篇关于PHP 5 Reflection API性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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