Optimising the Zend Framework

2019-01-16 21:46发布

I'm trying to get as much performance as I can out of my application, which uses the Zend Framework.

I'm considering using the Zend Server, with APC enabled. However, I need to know a few things first.

Is there any benefit of using Zend Server + Zend Framework, or should I just use any ordinary system to host this?

Shamil

4条回答
Explosion°爆炸
2楼-- · 2019-01-16 22:28

My tips for faster ZF (try from top to bottom):

Optimize include path

  • zend path first
  • models next
  • rest at the end

Use PHP 5.5 with OPCache enabled [NEW]

  • I can't stress this enough
  • gains around 50%

Cache table metadata

  • should be cached even if no other caching is needed
  • one of our application performance improved by ~30% on Oracle server ;)

Favour viewHelpers over using action() view helper

  • create view helper that access your model
  • or pass only the data from model and format them with view helpers

Use classmap autoloader

  • since ZF1.11
  • preferably with stripped require_once calls

Minimize path stacks

  • there are a lot of path stacks in ZF
    • form elements
    • view helpers
    • action helpers
  • each path stack lookup means stat call = performance loss
  • default classes are more and more expensive with every path on stack

Strip require_once

  • strip require_once from Zend's classes in favour of autoloading using find & sed

Favour render() over partial() view helper

  • no new view instance is created
  • you need to set variables outside the rendered view scope, inside the main view!
  • you can also replace partialLoop() with foreach + render()

Cache anything possible

  • small chunks that require lot of work and change seldomly (like dynamic menus)
  • use profiler to find low-hanging fruit
    • what you think is slow may not really be so slow
  • cache everything that can have cache set statically
    • see manual - Zend_Locale::setCache(), Zend_Currency::setCache(), Zend_Db_Table::setDefaultMetadataCache(), configs...

Never use view helper action() or action helper actionStack()

  • Never use them unless 100% needed - for example for complicated data output, but mind the performance loss they pose
  • They create whole new dispatch loop and are performance killers!

Disable viewRenderer

Try my superlimunal plugin

  • it merges included classes to one long file to minimize stat calls
  • get if from GitHub
  • measure performance gain

Server-side file minification

  • It makes sense for really big files - HDD is always the bottleneck
  • Even micro-optimization works fine sometimes
    • classmap with all ZF classes' paths is HUGE, striping whitespace and replacing long variables with $a and $b brought performance gain when having "dry" opcode cache and HDD under pressure.

Any opcode cache is of course a must have ;) (APC, ZendOptimizer, etc.)

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-16 22:37

Op-code caching is the one extension you always want to use when running PHP in production. Apc is an op-code caching and data caching extension but in Zend server the primary op-code caching is called "Optimizer plus" and I recommend comparing the performance between the 2 before deciding to use APC. There is also another extension in Zend server which does the data caching job. Many file includes (like in Zend framework) are no longer a problem with op-code caching since they are stored compiled in memory and does not take long any more to start using them.

Another major performance gain can be achieved with the full (paid) version of Zend server by using the PHP monitoring combined with code tracing which gives valuable information regarding problems and un-optimized code in your application. problems like long scripts and function execution, long DB queries, and more can be solved very fast with this combination.

查看更多
叼着烟拽天下
4楼-- · 2019-01-16 22:39

Zend Server is a very generally speaking PHP compiler (the P from LAMP or WAMP stack), however much more advanced, give you nice GUI to set everything (instead editing php.ini), but what more imported:

  • APC
  • Cache (data i page level)
  • Job quering
  • Advanced monitoring with debugging

If you looking for APC only maybe other solutions (what I do not know yet) could be cheaper, but need for APC suggest that you would like caching and job quering... I love it.

Zend Framework is not needed to use it, but you can use any framework (or without framework) you want.

Nice thing that you can try ZS full featured it for free for 30 days (APC is not availble in CE ---->>>> wrong APC IS avaible in CE)

查看更多
beautiful°
5楼-- · 2019-01-16 22:41

APC will help no matter what sort of stack you're running on. Any sort of OPcode caching will.

In terms of speeding up your application, the first step is to profile it. Use Xdebug to generate a cachegrind report and then use something like kcachegrind or webgrind to interpret it.

From working with Zend Framework, here are some pain points I typically find:

  • Config files are pretty intensive to compute. once you have the final config object, cache it!
  • File includes are really expensive, try and get them down to a minimum. If you're opening files a lot for reflection based stuff, cache the output there.
  • Database calls can be expensive, but are typically not the bears in the room unless they're central tasks.

Page level caching will help tremendously. Anywhere where you dont need fresh data, cache it.

Past that its less of a Zend Framework or a server issue and it starts being architectural in nature. Can you farm off intensive tasks asynchronously? Sometimes it's not worth optimising something, but it is worth changing user perception to feel faster.

Amusing thought, the other day i backspaced over $i++ to replace it with ++$i. It's technically faster, but I'm sure the time it took me to do that will never be regained in the programs lifetime. You have to draw the line somewhere :)

查看更多
登录 后发表回答