Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Framework or not (Cake PHP)

At university, my final year project was an MVC based c# web application.

My PHP is not strong, and I am looking to improving my programming skills in PHP and am looking to build a web application using PHP mysql.

Now why did I mention ASP.NET MVC??? Well because I quite liked the development environment, OOP nature of the programming and ability to program 'properly'. I also liked the MVC method of programming.

Now my question is.. For a relatively complex web application, Should I use a framework such as Cake PHP?

My specific web application will be performing the following actions: Quotation engine, XML, RSS Feeds, User Accounts, Shopping Baskets, Store quote for later, review previous transactions, online store management etc...

The site I am looking to build could receive up to 4000 hits per day and will be integrated within a wordpress plugin.

What are the advantages of using a framework as opposed to just hardcoding? Isn't learning a framework like learning a new programming language?

like image 613
Gravy Avatar asked Sep 18 '12 11:09

Gravy


2 Answers

Recently I was working with Cake and I am not overly impressed. It's not your best option. As advised you may try the Yii Framework. It's very well written. About the CakePHP I think the review I wrote recently should answer in details all your questions:

Quick and short - It depends!

And the long answer...

If you need fast web development process, then yes it's OK to use framework.

If you need fast performing website and you're expecting large load with a lot of database calls and complicated relational database queries then the answer is NO!!!

A lot of people are soooo impressed by the different frameworks, but they actually doesn't even know what the code of these frameworks does... And to prove that I am not just clicking on the keyboard, because I don't like certain framework or I'm just a framework hater I'll give you some facts on the not so bad performing CakePHP! :)

I like to test and crash web apps. Usually this makes my day... And that's my job! That's why I Love it!

Some info about the oven for our Cake

My Personal environments:

Local web server: Quad core second gen i7-2730QM, 16GB 1333MHz, 7500rpm hdd not that this matter that much..., default Apache 2.2, PHP 5.3, MySQL 5, properly indexed database.

Production: Dedicated blade servers *scalable cloud - top tier provider. Nginx, PHP 5.3, MySQL 5, Caching server

*The websites with just raw PHP loads in milli or nanoseconds.

Just FYI my CakePHP website have over 40 models and very complex relationships. Indexed MySQL database tables. Working in Firefox with most recent Fiddler 2 as benchmark tool.

I was recently using CakePHP for building enterprise website. I was able to test in all of mine environments recently starting with just the basic default generated page from the default CakePHP install. The load on my local web server is 3.9sec in production 4.5 seconds, and this is just the default page after Cake install?!

The results are before tuning the Cake (Assuming that the people who bake the very first Cake know how to properly handle the ingredients and assuming that the App will run FAST! I doubt that.)!

The master tune ups:

Here's what works for me and was tested: Caching: The Current CakePHP 2.1 supports File, ApcCache, WinCache, XCacheEngine, MemcacheEngine and RedisEngine. No matter which one you choose the approximate speed increase is from a 100% to 180%. (We don't use the Cake's caching options, we run our own caching server) In our case 220%! Set Debug to 0 - for the Cake engine to run need to generate 2 cache folders. The first is /tmp/cache/persistent - there are two different files here that are used by Cake when you run your app.

The one that slows down the Cake generation is cake_core_file_map. This file stores various classes in your app. For building the file Cake does a logical and time consuming search of your directory tree looking for the right file.

The second cachefolder is /tmp/cache/models this folder will contain all the files for every model that your system contains the table schema.

What's the difference when Debug is 0? When Debug is 1 or greater the cache lifetime is 10sec. When Debug is set to 0 the cache lifetime is 999 days. The approximate speed increase for baking the Cake is from 80% to 100%. Persistent Models - turning ON "var $persistModel = true" Will generate two new files in /tmp/cache/persistent for each model included in the controller. One is a cahce of the objects and the other is cache of the models in the ClassRegistry. This cache can be saved only on the file system. Approx. speed increase from 0% to 200%. Depending on your app and the number of the models.

Other tips and tricks: Avoid using $uses, because makes extra loops and hits the ClassRegistry. That often is WRONG! Cookies are encrypted by default and the cypher crypt method is very slow. If you're not storing any sensitive data, turn off the encryption. Performance improvement of 0% to 15%. Use GZIP compression no matter what (will compress the output up to 90%)! If you're using any FRAMEWORK, USE the VERSION THAT IS builded with PHP 5+!!! The documentaiton about the CakePHP is a lot better than the one provided couple of years ago. What makes CakePHP slow mostly is improper code usage from the developer. But it's not easy to develop app, if you don't really know how the Cake is working.

I've been reading a lot of comments that some functions doesn't work in Cake. All of the functions in CakePHP works as stated in their cook book so read carefully. Some are not explained very well or in details (that's why it's not for beginners), but it doesn't hurt to ask! Sometimes certain function have to be used in the proper order to work, else your app will crash or will not return the desired results. Keep the models in mind and how the different classes and functions work!

Seems that the people wrote this code at time to time doesn't know what they're talking about either. For example sorting array from the database using Cake's array sorting function instead of the MySQL sorting capability, just because it's cool? Seriously? And this was written in the documentation of the Cake.

Oh speaking of databases... we're using ADODB with Cake which is making the things a bit slower too. But the ADODB discussion is for another article. Just another speed sacrifice, but we always work for cross platform compatibility!

The whole Cake works with a lot of arrays and generates and relies on a lot of complex models. Some other mistakes I found is using slower functions and methods than another in the code. But I know very well it's easier to find the mistakes of someone else than your own!

Speaking about time development, there are some things that you may face during your heavy development process with CakePHP that are not easy to do and you may end up spending a lot of time figuring out a way around.

So overall if I have a very complex project which I usually do and I can't easily find or build the required functions to do the complicated job in Cake or waste few days busting my head in the wall, then I don't know if baking a Cake is worth it! After tuning the Cake, the speeds were close to the speeds of our other apps. But after few days in load testing seems that the web app is holding up, but still bending under the pressure of few thousand visitors. I'm expecting overload pretty soon after passing 7.5K unique visitors!

I would say that Cake is for Advanced or Intermediate developers. If I was just at the beginning of my web development career I wouldn't use Cake. For small to mid-size projects it's fine or for building administration councils (it's awesome!). For a large scale projects with a serious traffic load unless you want to spend solid amount of money on servers for feeding your app, I wouldn't go with any framework, but just bare raw PHP (may be Smarty - which is made for performance)! Remember that there are constant hardware and software updates and upgrades and your app is also depending on that. Imagine the migration or debugging of very complex large scale app based on a framework - software versioning, hardware upgrades, etc... Think about the risk factors and the actual support of your app!

For a large scale projects I would stay away from open source platforms like Wordpress, Joomla, Drupal, etc... The best way of building scalable well written app is to build it on your own! That way you'll know what's behind it! Remember! - Compress, Cache, Store when possible in the database, Optimize, Use less images in your web design, avoid complex URL rewrites. And Optimize again! Go thru your server access and error logs and Optimize again! :) Every optimization and speed up you make will pay you back when you start hitting the 4 digit number of visitors and over.

In my over 14 years of web development experience I've learned from my mistakes and I know when and where I need a framework. A bit of reading and project planning time about your project will save you a lot of time and money than making a mistake and learning. Time is money!

Hope this helps someone improve their development time!

I'll keep testing and benching and post the updates later on here!

Source: bit.ly/OX3UTo

like image 159
GTodorov Avatar answered Oct 22 '22 09:10

GTodorov


As a person with experience in about dozen php frameworks and self assessed as proficient in a few (Cake included), I would suggest you look into Yii Framework. It is lightweight, efficient, well written, supports huge amount of features, has big and friendly community and is by all means better then CakePHP imho.

As far as the 4000 hits per day - that's basically nothing. If you write well optimized applications (take care of slow queries, optimize the db accordingly, move heavy traffic content to CDN eventually), on a decent server, web app can take many times that amount.

like image 28
ddinchev Avatar answered Oct 22 '22 08:10

ddinchev