When do we have the necessity of using the frameworks in PHP. I have heard about zend framework and symfony. I have read about them but still didn't understand that exact point why we use the frameworks in software development.
Frameworks often provide you the boiler plate code that you would have to otherwise use, such as: Session Management, Templating, Database access etc etc.
In terms of proper software engineering, using these frameworks tend to promote proper design with patterns such as MVC(Model, View, Controller). By using this pattern, you can increase code reusability, separation of concern, etc.
By utilizing the database access that these frameworks provide you, you can write efficient models that can interact with the database while promoting code reusability. Another thing to consider with databases is security, such as SQL injections. Most frameworks now-a-days will automatically protect you against these type of attacks. If you were to write your own code(without a framework), you could end up leaving some sort of query wide open for sql injections.
For controllers, these frameworks tend to provide some sort of URL mapping. An example might be domain.com/posts/edit/5. The framework will then parse this url, and call the controller "posts", method "edit", and pass in the id 5. As you can see, if you weren't using a framework, you'd have to write all this code yourself, which would increase the amount of time coding and more chance of mistakes.
For the views, often times templating systems are in place to help reduce the amount of html, css, javascript etc you write. Not only that, they also provide structure for your views. In other words, they help you put your views in directories/locations that make logical sense(in terms of reusability, ease of use, etc).
Summary:
Because of all these features, you can see that not only will this reduce the amount of error/bugs in your system, but also decrease the amount of developing time.
Of course there are downsides to everything, and this is no exception. The main problem is the learning curve of learning these new frameworks. Often times frameworks provide so much that you have to learn all these new features just to get up and running.
Some popular PHP frameworks:
CodeIgniter
CakePHP
Zend Framework
Symfony
Getting Started Guides:
CodeIgniter
CakePHP
Zend Framework
Symfony
In terms of never using a framework before and wanting to get started, I'd highly suggest CodeIgniter. The learning curve is no where near as high as the other ones, however provide enough boiler-plate code and features that it should get you up and running.
If you want to do your own research(which you should!), here is a comparision table of all popular PHP frameworks:
http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#PHP_2
Frameworks are usually used to accelerate the development of a project. Imagine having a bunch of extra new functions to help you with things like logins, page generation, database management, etc.. on top of the basic php functions. Basically Frameworks are made to save time and stop reinventing the wheel every time you make a new site/etc...
I have used CodeIgniter to build a few website and web applications.
The main advantage is that you get many pre-built components such as database abstraction, sessions management, email sending tools, and so on in one consistent interface and one package, so you don't have to spend time looking for these components that may or may not work well together.
Each framework has a different feel to it, a learning curve, limitations, you need to try them out and get a feel for it.
Many years ago, I was using Macromedia's Dreamweaver with a 3rd party extension to build my web applications. Since that time, Dreamweaver is owned by Adobe and the 3rd party extension is off the market, so I have legacy code with no support. For me, being messed around my market forces gave me the incentive to seek out a framework that was "desktop independent".
Summary: As a web developer, the primary benefits of a framework are ease of use, reusable components and greater control over rate of obsolescence.
Another point not made (i think) is that regardless of framework, but assuming it is well made, mature and has a community is that it has a structure that is imposed on the developers, whether it be MVC or REST, that future developers can quickly get to grips with when extending or maintaining the codebase.
So the naming convention for classes and objects & structures, the structure of the files and directories , the location of third party code, the templating system, localisation/internationalisation etc. in a well designed (and mature) framework will be well defined and accessible through third party or community maintained documentation.
Related
I'm a beginner php developer who is trying to build a social network for my school students. Knowing that the school has over 1000 students who are already active, I must have a plan of expanding / scale the code that I write.
Earlier it was just the LAMP Stack, now the modern web development is way more than that as I see, I'm truly kind of lost in what technologies to use and how to incorporate them to build a scalable app. I'm hoping to divide this application into 3 layers.
Application layer (phalcon,reddis,apache,php)[mvc api centric]
Database layer(mysql)
UI layer - (html/css/js/)
This is where i need help, is this design approach good for a scalable app ? where can i improve ? any explanations, links for further reading will be a highly appreciated.
Welcome to SO. I cannot think of a particular reference guide to direct you to (although the PHP manual is a good place if you end up stuck with how to do something specific). I would suggest reading a bit of several results when you search "Getting started with MVC in PHP" and noting what they agree on. That said, take a look at what I say below (and then ignore it as much as you please ;) ).
Firstly, you are wiser than many in sorting out a scalable design before launching into the project...
I'm excited to see Phalcon in your list there already. However, as DevDonkey suggested, start with something simpler first (Phalcon is very powerful but to really get to grips with it you need a good grasp of PHP, particularly object-orientated programming).
If you are completely new to PHP...
... try building a small app (products table, view/add/edit/delete functionality) and learn the beginnings of the language that way, as this answer suggests. Things will go wrong and you'll discover lots of headaches when you want to change one feature and it affects everything else but that will help you to understand the importance of...
MVC design
From your question I can see you have at least heard of this. This is really where the layers of your application lie:
Model - interactions with the database (retrieving/editing data) are handled through this. So you could have a MYSQL database and then your models provide a nice interface to interact with the data (generally you have one model for each table).
View - this is the last layer, what the user sees. So you will make use of your html/css/js knowledge here. On this topic, unless you really want to do your own css consider using a CSS Framework such as Bootstrap. It will really help speed up making your site look good and there are loads of free templates out there to use with it.
Controller - this is the application logic. The controllers request/manipulate data through the models and then decide what to send to the views for rendering.
Use a framework?
Using a good framework can make your application more reliable and quicker to build. But using a framework without understanding it will be frustrating, slow and possibly result in worse code than if you didn't use one to begin with (as you employ hacks to get around the pieces of the framework you don't understand). My current favourite is Phalcon but as a relative beginner to PHP I would suggest something more like CakePHP although both Laravel and Symfony are also popular.
Summary
Start small, learn, test ideas out and then build up to a bigger project.
Get comfortable using PHP (including OOP style) before using a framework.
Use an MVC framework
The layers you laid out in your question are good, but I would split it slightly differently (considering that MVC is the 3 layers)
Application Layer - controllers, written in PHP, handles logic/manipulation, often the biggest layer
Database Layer - models, written in PHP, you will also need a database which could be in your favourite database language - MySQL ;)
UI Layer - views, possibly written in PHP (depending on the framework) but also HTML, CSS and JS as well as well as a templating language if you wish (e.g. Twig or Volt), essentially a way to make the response from the controller nice for a human
First Project (for CakePHP)
This blog tutorial is a good place to start if you decide to use CakePHP.
Getting started with Phalcon
Phalcon is more powerful/verstile, but to get started with it I feel you have to be a better PHP developer than you do to get started with something like CakePHP. Take your time to understand each new concept with Phalcon, particularly Dependency Injection.
Even having used CakePHP for the past 2 years and being familiar with MVC patterns and PHP, I still worked my way through all 7 of the tutorials in Phalcon.
Having said this, my favourite thing about Phalcon is that it is highly decoupled - so it is fairly easy (after a while) to replace bits of it with your own extensions if it doesn't quite do what you want.
Note about Phalcon: It is not as popular as many other frameworks (although popularity is growing) and so you may have to spend some time digging around when you get stuck. However, the docs are improving all the time and the forum is very active. Unfortunately the number answering questions about it on StackOverflow is still small compared to many other frameworks.
We are starting off on development for a web based portal in PHP which is starting of as a prototype but is expected to grow into a considerably large system.
Performance is a key issue as the system should be scalable enough to support a large no. of users (100k users for e.g)
In the process of deciding upon a framework, the options we have are:
1. Use Core PHP/Smarty templates
2. Use a framework such as Laravel.
What are the pros and cons of using PHP/Smarty templates v/s Laravel considering performance as the key factor ?
Is it still worthwhile considering Laravel despite the performance hit it will have as compared to Core PHP or a simple templating framework ?
If the question is: Is an application built with a framework slower than native code ? Then the answer is: Yes, less or more, a framework uses abstraction layers to simplify the development process and it (Framework) may take some extra time than native PHP code.
Does that really matter ?
I think it is not a problem at all, not enough time (difference) that one can catch the difference and a good framework is also built that keeping on mind. If you use a good framework and also properly write optimized code then it's fine and you don't have to worry about it.
Depending on the size of your project you should decide what to use and for a big project I always prefer a framework. There are many benefits for using a framework, such as a framework at first helps you to do more with less code, gives you unified API/Tools to accomplish complex tasks easily with less effort. A good framework gives you build scale-able and maintainable application and most of those are well organised, tested and maintained by a community so you may get help from the community on many situations.
Also, when developing application with many team members, it is much better that everyone is working on the same known documented framework, which might not be the case with your own archive PHP code and a framework also unites the team members to a specific convention of writing code because everyone follows same rule provided by the framework. It's also easy to recruit additional team members anytime who knows that framework and new team members can easily fit into development process.
Since, you said about 100k users, well I think it's related with the database than coding, if you have an optimized database then it may give you query result faster and yes also depends on queries you write, they also must be optimized.
So, I think you should use a framework and obviously make the decision by discussing with the team members you have right now. Laravel is a good one but there is a different candidate only for performance/speed and that is Phalcon and it's different than others because it's a compiled framework (c library) and that's why it's faster than others and maybe the fastest one so far.
But still, you should think about Laravel or suchlike one because Laravel has so many ready packages and support community than Phancon and it's easy to find help for a well known, widely used framework. These are my opinions but consider to use a framework, it'll make your life easier.
Performance benchmark of popular PHP frameworks (Source):
I'm about to start building a fully functional penny auction script (something like bidhere.com) in PHP/MySQL.
I know PHP preety good and have no trouble using the manual.
My question is: Should I learn some of the PHP frameworks and use one of them in completion of a project this sized?
Since you are dealing with money, using a framework might help you in the security front. A lot of the really good frameworks have been hardened against basic hacks (e.g. sql injections) so I would recommend using a framework.
If you write everything by yourself, you run the risk of being attacked and losing information (or worse, money).
Just my 2 cents (does that mean I get 2 free bids?!?)
Using a framework will mean you're not re-inventing the wheel.
It will also keep you abreast of new security patches, and you will have confidence that attacks like CSRF and XSS have had measures implemented against them.
They're by no means perfectly secure, however, it will remove a lot of worry from your mind, and the minds of your clients if you choose to sell/lease the script.
Frameworks are a good idea in general. Since the framework is usually native to the language, you are really just extending your reach into the language itself.
Frameworks keep you from having to write code that has already been thought about and implemented elsewhere. But also frameworks tend to offer many other benefits as well, such as MVC code organization, handy HTML Form/Url helpers (codeigniter), independent 3rd party modules (drupal), and a slew of easy to manage configurations.
Having access to ready-made code makes your job easier and allows you to be more graceful and efficient in your implementation.
That being said there is no preset rule that you have to use a framework, if you know what you are doing, you have a straight-forward scope/objective and the task at hand is not complex, then just using raw PHP would benefit in this case, especially due to the fact that different frameworks have differing learning curves.
Certainly a framework, but which one. Points to consider:
If you are dealing with the backend operations, you better create backend separate from fronted. That's what Models are used for. You would need a framework which separates business logic from the presentation logic.
If you will use lots of forms and user interactivity on the site, then you need to have PHP UI framework. That would help you not to worry about how you are going to submit forms and focus on functionality.
If you are familiar with few of the frameworks, then stick with them. If you haven't used yet, then shop around. There are few general purpose ones which you have heard of, but then there are some you haven't heard of. Compare them and see which will get you from A to B within minimum time and effort.
I have ready numerous posts here on SO about framework1 vs framework2 however it seems to be alot of personal opinions that are one sided. Based on the following can someone tell me which framework would be ideal for my needs?
Build a rich featured API where other sites and devices can use the API to use website features and access it's content.
RSS Feeds with both XML and JSON for jQuery interaction.
Ability to use layouts / templates that are customizable.
Use of plugins so that I do not need to duplicate code.
Database querying with relationships.
GREAT documentation.
Actively supported.
Doesn't REQUIRE command line access.
Easy to manage file uploads and move the files around so only certain users can download them.
Customizable access level so users can have different access levels depending on which project/section they are viewing.
Low overhead usage.
SEO URLS that do not require the '/view','/edit','/add' in the urls (depending on which action you want to do.)
Support for jQuery
There have been a few frameworks I have seen that support some of these but not all. I am currently using CakePHP for one project but do not think it would fit my needs as the database querying can get horrendous. I have heard a little bit about CodeIgnitor however it doesn't seem to easily use templating (maybe I just misunderstood what I read).
If you could tell me which framework you think would be ideal for these needs and why that would be very helpful!
I'll just spamvertize my little framework overview table here. The simple table answers a few of your technical points:
http://matrix.include-once.org/framework/simple
Use the detail/feature view to cherrypick your options.
RSS isn't a standard feature even with the big frameworks, use a PEAR library
templates: all frameworks use them
plugins: depends on your concept of plugins, most frameworks are extensible though
look for "ORM"
GREAT documentation: that would limit you to codeigniter or cakephp
Doesn't REQUIRE command line access: except symfony+cake, few do
file uploads: this isn't a standard feature, but I'd just mix and match a library
Customizable access level: practically all frameworks come with a permission system
Support for jQuery: this is surprising. Prototype seems to be very strong, only half the frameworks use jQuery by default
CakePHP database querying doesn't have to be horrendous. (Though, I remember my first few projects were definitely hard on the database)
With the right optimization, normalization/de-normalization of your data, and a few tweaks here and there (persistent models comes to mind), you can accomplish everything you've inquired about with CakePHP, and keep your database load to a minimum.
That said, if you truly want to move to something else, I'd go with Zend Framework.
Symfony is bloated, (and yes, fanboys, this is still true).
Codeigniter is super lightweight, but you're going to be doing a LOT more work to accomplish your listed requirements. I've spun up two codeigniter applications, both relatively simple, and both took twice the work / twice the amount of new code than if I had gone with say, CakePHP.
A lot of religious fanaticism floating around when you talk about frameworks. But take a look at the documentation of Fat-Free Framework. It just might catch your fancy and requirements.
Before I answer, let me qualify that I'm certified on Zend, a frequent user of CodeIgniter, and daily user (and hater) of Symfony.
Zend's setup, especially if you're doing a small-medium sized site can be ugly. Especially using the data mapper strategy, you're talking a thousand or more lines of codes just for the model setup. CodeIgniter is much better setup-wise, but still not insignificant.
Command-line free --essentially-- knocks out Zend. It's doable, but not fun (see thousand lines of code, above) Built-in user auth isn't nearly as good on CodeIgniter as Zend, perhaps that's a serious knock....definitely no templating there. Symfony is flat-out done because of the addition of /view /edit, etc.
Hate to break it to you, but it seems that many users of all these frameworks are not native English speakers. Forget about Symfony, seems entirely eastern-European based. I'd hate to be a new-to-php user of Zend Framework with all the competing tuts with their assumptions of some semi-complex concepts. There's a reason that Zend's training is expensive and full.... Again, CodeIgniter is not horrible, but still can be frustrating.
Simply because of our extensive use of Jquery and desire to avoid a ton of hack-around, my company has dumped the frameworks altogether. Now setup is purposeful, not for a framework...just build a DAL, assemble classes, build views, and done. Established functions are re-purposed as "plugins" that we actually know and understand. Most interaction is Jquery based Ajax (sometimes XAJAX) which really doesn't take advantage of the frameworks anyway--and fights tooth and nail with Symfony. For those who argue that frameworks force MVC, I have a VP of Development who does that just fine, thank you. Perhaps it's not the right answer for you, but we're glad we went this route. It's saved weeks worth of documentation-hunting.
I want to know which php architecture strategies developers use in complex php applications . So far , i know the mvc structure which consists of models, views and controller (and controller plugins which handle with common tasks such as user access controller ). I know some good php frameworks which makes some common stuffs easier .But the problem starts when i thing about huge and complex php applications . because in these applications there are lots of stuff to do or lots of think to check, so i can not decide which code should be where .
Think about magento application , this is very huge application . when i review the source code of application , i can not understand the design strategy . i know there are some perfect design strategies which can handle very big php applications easily , because they can not build such a huge application with a very weak design strategy .the design strategy should support more than you want , so you can improve your code and application easily
To sum up , i want to how can i create bigger applications . Now the design strategies i use in my applications limits me , so i can not create more complex applications . i want to know which the design strategy can handle complex applications.
i know this is very abstract question , but this is because now my php background coming from amateur hobby not from academic . i want to do more , but i am in somewhere where i can not go one step more , because i can not find more complex info about coding . whatever ,to sum up , i want to know about design strategies for complex php applications such as magento .
Maybe the design strategies which i know (mvc , frameworks ci cake ...)can handle more complex applications than i think ..
if there are some mistakes in my questions please feel free to correct them , sorry for my inadequate english ..
I believe that part of your problem may lie in the fact that creating enterprise applications is a problem in any language, and the design patterns that can implemented are actually language agnostic.
I would strongly recommend that you familiarize yourself with Patterns of Enterprise Application Architecture by Martin Fowler. This is the seminal work for any other books that you may later pick up that cover the same concepts in a language specific format, and if you want to truly understand what is required to create robust, scalable applications on the web then you'll need to familiarize yourself with this book.
A very common and popular design strategy with web applications right now is the Model-View-Controller paradigm. This has to do completely with separation of concerns in your application so that you aren't mingling database access code with html output.
For a pretty good treatment of the topic I would suggest that you look here (Zend Framework specific but it covers the general topic well) and here for a discussion about Models specifically. Or if you want to look at a more generalized PHP MVC tutorial, Rasmus Lerdorf has one.
In addition to this (and again you can learn this from PofEAA by Martin Fowler) you will need to learn about Object-Relational-Mapping what the strengths and weaknesses are of the various design patterns.
Unfortunately there are many good ways to do things depending on your needs, but for every good way there are about a zillion horribly wrong ways to them.
Which frameworks have you examined? Examine symfony, Zend Framework, and CakePHP if you haven't already. And by examine, I mean actually write medium-sized applications using these frameworks. Simply reading code is often not enough to get a grasp of how it works. You often have to actually use it and try to modify it.
You may also want to check out the book PHP 5 Objects Patterns and Practice for some ideas of design strategies that you may apply to your application. You may also learn quite a bit by studying frameworks written in other languages. The designers of many of the PHP frameworks were heavily inspired by Ruby on Rails, for example.
It is indeed very abstract question and "very complex" is not very specific. When I hear people talking about "complex" applications I associate it with
a) Someone is using a complex architecture for a simple Problem. E.g. by using every design pattern and framework that sounded cool.
b) Someone tried to squish tons of entirely different usecase into a historically grown application, creating and using proprietary and undocumented interfaces and couple everything as tightly together as possible. Unfortunately CAN build huge applications with a bad design strategy and that is what makes them complex.
c) Legacy systems and Legacy System integration (ok see b)
Magento may be a big application, but the underlying Framework is still the Zend Framework, mainly its MVC part. So reading the Zend_Framework documentation will help you a lot to understand Magentos architecture as well (I won't recommend it the other way around by trying to dig into the Zend Framework through the Magento source).
I would recommend to actually start building a bigger application with one of the MVC frameworks yourself, because that is the best way to learn the architecture and its benefits and where the limits are.
If you haven't already, you should look into Object-Oriented Programming. There is a really great tutorial about that here. I think this is perhaps the most important thing that big web apps do that isn't necessarily intuitive to the amateur (myself included). The trick in MVC frameworks like Code Igniter is to build a series of classes (or objects) as either models or libraries.
Well, even if your question just all about PHP... If you handle your static content like images with PHP it will result poor performance no matter using you MVC or not. You should use front end like nginx for such things.
look at http://highscalability.com/ real stories from real life!
Also note NoSQL.
Catalog of Patterns of Enterprise Application Architecture
.
I tried to understand your problem and found that magento architecture is very powerfull but complicated. I got a solution by Zendfox, It is a web application framework, suitable for small to huge application development. It has very cute application architecture that can be manage very easily. It also has module developer to create custom modules for zendfox within few minutes wizard based tool.
So take a look at: http://www.zendfox.com