Zend Framework 2 large page load time - php

I have installed the Skeleton application of ZF2 (from official GitHub repo), and the first page I see takes 400-700ms to load (default "Welcome to Zend Framework 2" page, with no database connections and without handling anything).
In raw PHP (without frameworks) It'll take a few ms. to load.
Could You explain, what caused such a big delays?
I'm new to ZF, and now deciding, to use or not to use it.

Zend Framework is a heavy php framework which uses a lot of php files. Because php is evaluted on the spot it takes a lot of time every request to evaluate these files. You should use a Opcode cache like apc and many others or if you're using php 5.5 Opcache that is built -in. An Opcode cache makes a copy of these evaluated files and stores these in memory. This gives a huge speed bonus.
Another thing that might be the problem is that if you run this ZF2 application with apache on windows it is much slower then apache on linux

It's hard to know whether this is good or bad without any info on the server you're running this test on. You also implied that this was a stock ZF2 skeleton app, but your screenshot shows what I think is the ZF2 developer toolbar, an add-on module.
I just tested a fresh checkout of the skeleton app on my (admittedly decent spec) dev machine and it loads in 30 ms (PHP 5.5). I would expect to be able to improve that with some simple production-type optimizations (classmap, config caching, superluminal etc.).
Edit: I thought I'd see what I could get this down to with some quick tweaks. I also installed the developer toolbar just to be sure this wasn't slowing things down too much. Result:

Related

Config apc in zend framework 2

i need to maximize performance in a zend framework 2 + doctrine 3 project , the application is slow so i've woked in enabling the memcache for some queries , i've also enabled the cache for the config files ... but the application stills slow so searching in the net i found some articles talking about performing zf2 project and mentioning apc as a way to make the application not so slow , so i've installed apc, but i can't find a way to configure how to enable apc in zend framework 2?
APC is a PHP extension, it's not something you need to enable within individual applications unless you're using it for userland caching as well (which I assume you are not, since you mentioned memcache). You can check if it's working by firing up a phpinfo page and seeing if you have an APC section.
If you have PHP 5.5 or above, you don't need (and shouldn't use) APC, as PHP comes with its own (better) opcache.
I'd suggest you benchmark your application using something like XDebug to find out what is causing the slowness. This should give you a better idea what you need to improve.

using both Opcache and Xcache

I'm just wondering is it stupid to use both Xcache 3 with Zend Opcache at the same time to cache PHP files? I know that both do almost the same job, but not sure if that would make any difference on the performance and speed.
I want to speed up my php page load so that visitors don't need to wait long.
any thoughts on that?
To answer your question: Yes, you should not run xcache and Zend Opcache at the same time. If you do, you'll get undefined behaviours, most notably "cannot redeclare class XYZ" fatal errors. That happened to me after a systems upgrade, where the packet maintainer activated Zend Opcache along the already existing xcache installation.
As for the matter of which of both to use for opcaching, that depends on your specific code - I'd recommend setting up a test environment and firing up the Apache Benchmark or a similar tool to check the answer times.
On a default wordpress installation, I was able to get a speedup (uncached vs xcache) of about 5-7x, which is quite significant. If you really need more, you'll need to check out the other possibilities already mentioned in the comments like
using a loadbalancer and multiple application servers
using memcache or memcached to cache database queries and other load heavy operations
switching to another database system like a NoSQL system (be careful of the consequences)
changing your architecture to a static site with webservices providing interactive content

Is there any real advantage to use zend ce server over just referencing (include) the zend framework library?

I'm new to PHP frameworks, and currently I'm trying Zend Framework (ZF). I'm old fashioned when it comes to installing software, I like to install apache/mysql/php all separetely since I find easier and it gives me more control of it.
It seems that the "encouraged" way to develop with Zend Framework is using the Zend (CE) Server. I personally don't like this idea of a app install everything else (PHP/Apache and so on).
From what I've seen if I include Zend Framework Library in php.ini path I'm ready to go. So is there any real advantage to use the Full Zend (CE) Server??
You don't need Zend Server, especially if you're fine with setting up your own environment. On the other hand Zend Server is optimized for running Zend Framework based applications. It becomes especially meaningful when you start using Zend Studio too. There is just a smaller probability of there being any kind of issues in your AMP stack.
Apart from that, Zend Server really is a great stack. Much more advanced than all the *AMPs out there. You can for example activate and deactivate PHP extensions through a nice web GUI just by clicking a button.
If you are already developing with apache/php/mysql stack on your machine, I see no advantage to install Zend Server. As far as I can tell, Zend framework is just plain PHP, there is nothing special in the code that makes use of any Zend Server functionality.
I got my info form wikipedia : there is simple comparison
between the both
the CE version misses these spec :
Page caching
Application monitoring ,Does runtime monitoring of individual PHP requests several different conditions
Function Error Database Error Slow
Function Execution Slow Query
Execution Slow Request Execution
High Memory Usage Inconsistent
Output Size Uncaught Java Exception
Custom Event Fatal PHP Error
PHP Error
Application problem diagnostics Zend Download Server (Linux only) - Allows for large content, such as videos, to be downloaded without tying up an Apache process
Software updates and hot fixes
or you might find this page is helpful : http://www.zend.com/en/products/server/editions
but from my point of view : you can customize your apache/mysql/php to be identical to the CE version

Seriously speeding up PHP?

I've been writing PHP for years, and have used every framework under the sun, but one thing has always bugged me... and that's that the whole bloody thing has to be interpreted and executed every time someone tells my server they want the page served.
I've experimented with caching, FastCGI, the Zend Job Queue (and symfony plug-ins that do similar - as well as my own DB-based solutions that implement the System_Daemon class to run background processes) and I've managed to make my apps fairly quick using all that stuff... but I can't get over the mental block that my settings files, system/environment check functions, and all the stuff that should only really be loaded ONCE... loads every darn time someone hits my page.
So, my ramble leads to the following Q--
Is there some method/technique for loading certain aspects of PHP into RAM so that when that page is requested, all my settings.yml files, system checks, framework files, cached pages etc can be loaded directly from memory without ever even touching the HD... or needing to go through the same loading mechanism 50,000 times per day to init the program?
If there's nothing in PHP... are there any other 'web' languages that can be compiled in this way, to allow for true init-once apps?
I think you should give memcached a try, if you're talking about caching data. I think PHP is fairly proficient in caching compiled php-pages if you use stuff like mod_php in apache (which doesn't die in between requests).
Take a look on APC (Alternative PHP Cache), it keeps a cache of compiled files (PHP Opcode) and also lets you store random variables on memory with apc_fetch, apc_store.
The instalation is very simple and it really gives a boost on performance.
Create a full page cache on the ram disk and make your web server serve the page from there. This is a method that wordpress supercache plugin uses and it works great if your web site is suitable for full page caching. This whay you are not even invoking the PHP interpreter.
For users that are logged in (have an open session) you can create a rewrite condition that will redirect their request to the PHP engine.
Also, always use an opcode cache like APC and use it for caching config files (memcache is also fine).
If you are asking for a JVM/Tomcat like application server, then the answer is likely no. To my knowledge nothing (usable) like this exists for PHP. PHP uses a shared-nothing architecture, so it is by design everything is setup on all requests. But actually, this makes PHP scale pretty well.
As for speeding up your apps, try to use memcached and a code accelerator. Maybe look into Zend Server to get a complete package.
Regarding your last question, I believe at least most of the Python and Ruby web frameworks work like that.
Ruby web applications are nowadays built so that the app is only initialized once per server process. When requests come in, the server (Apache, for example) passes them to the web application (over Rack interface) which is running on the background.
This is how web frameworks based on Rack work. Older versions of Ruby on Rails were similar, although they used a different interface to talk to the web server.
I'd keep an eye on the Facebook Engineering ppage (http://www.facebook.com/notes.php?id=9445547199), every now and then they come up with posts about how they keep things fast/optimize/scale. I think they're use of php is super impressive.

should I add a php APC to my server

A friend has recommended that I install php APC, claiming it will help php run faster and use less memory
sounds promising but I'm a little nervous about adding it to my VPS server
I have one small app that I've built using codeigniter, and several sites that use the popular slideshowpro photo gallery software
could install this break any of the back end code on my sites?
I'm no high tech server guy, but should I give this a try?
Depends entirely on your situation.
Is your site unresponsive or slow at the moment? Is this definitely due to the PHP scripts and not any other data sources such as a database or remote API?
If you answered yes to the above, then installing one of the many PHP accelerators out there would be a good shout. As for using less memory, that's largely dependent on your apache/lightppd/nginx config and php.ini variables.
Most PHP accelerators work by converting the (to be) interpreted PHP code into opcode. This is then stored in memory (RAM) for fast access. If you haven't already implemented file-based caching in CodeIgniter then the benefits of installing a PHP accelerator would be noticeable. If you haven't, then I suggest you do that first before moving straight over to (wasting?) spending time trying to install APC manually.
If your site is currently performing well and you're not too confident in your *nix skills then I suggest you try implementing CodeIgniter caching first rather than try messing with what is an already working VPS.
My personal preference is PHP eAccelerator.
Should installing a PHP cache engine not improve your site's performance then I suggest you look at what other factors influence your application. As stated above, these could be: database or API to name a few.
Hope this helps.
APC is basically a cache engine that stores your compiled php scripts on a temp location on your server. Meaning that these do not have to be interpreted every time someone calls your sccript. It is a PHP extension can can safely be turned ON or OFF and it does not affect your actual code. So... do not fear!
When a php script is processed, there is a compilation phase, where php converts the source code of the php files into "opcodes". APC simply caches the result of this compilation phase, so it should be safe to turn on.
That said, when making such changes to production code it is always wise to run a regression test to ensure no new issues have been introduced.

Categories