Related
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.
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.
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 am working on a Facebook game which is developed using Zend framework. Right now I don't have lots of traffic and already seen quite a large # of data usage / CPU time.
Actually, I'm not good at Zend. I good at coding from scratch for both PHP & JS.
so, I am curious about the performance of Zend framework. becuase I'm thinking about rebuilding the applciation using Zend as the backend to manage the data / session / logic. and use JS (native code or JQuery) for the front-end rendering UI and handle user action in the client side.
In between, use aJax to get data from Zend backend.. most likely REST.
Anyone has suggestion about this kind of structure? I want to cut down the server load by that and also easier to manage code, plus better user experience.
Appreciate if anyone has good idea. :)
(POST few days later)
so, baseline PHP should be faster and use less data transfer (if code correctly) then Zend (or any) framework, right? Code reusablility is not a big concern here. :)
One thing many php developers fall victim of is sacrificing good architecture and sound principles for what they perceive as performance.
You may decide to cut corners in your code, but remember, "premature optimization is the root of all evil". So if you need to optimize early make sure that you're actually doing something useful.
The Zend libraries are engineered with best practice in mind, not necessarily performance. The rationale is that there are many ways to speed things up later without sacrificing code maintenance and readability (caching, load balancing, hardware, queue management, etc).
That been said, I don't think what you're looking for are statistics on ZF's performance, but rather advice on how to setup your application with it. Specifically, I'd advise you to create a dedicated, very light bootstrap for ajax requests. In ajax, you would normally only need some minimal prerequisites before dropping inside your controller. For the non ajax requests, set them up normally using the recommended architecture (bootstrap, front controller+plugins, controller+helpers, model+views+helpers).
My personal rule of thumb is that if I only am going to serve about 100 requests throughout the day, then there's very little reason to optimize anything. When the application starts feeling sluggish, if it generates enough revenue, maybe I can get a dedicated server, if not, there are always solutions such as apc, memcached, beanstalkd, etc.
Here's what you're looking for: PHP framework comparison benchmarks
Zend Framework vs raw PHP code tends to be close to a 1:500 requests per second ratio.
If you have a lot of time and not a lot of money, develop in raw PHP. If you have little time and enough money, develop in whatever is fastest without regard for performance...you can always add hardware later. If you fall in between the two, balance it as you see fit.
As much as I dislike it, CakePHP is faster to develop in than ZF, so it's great for time crunches. CodeIgniter is faster than either, but doesn't have as much built-in, so it's closer to the performance end of things without going to raw PHP.
There is only one thing to do first if you think that a ZF-based app is slow. Measure it. Various tools exist that will take the profiling output of Xdebug to show you which parts are slowing down the process, then you can make some moves towards optimising those parts (such as a lighter weight initialisation, and/or some caching). One good resource is the the Zend Framework book at survivethedeepend.com, "performance optimisation for ZF Apps".
In my opinion, benchmarks of frameworks are useless. They say something about an abstract situation, but performance is very situational. You should measure your application and optimise that. Yes, there's probably a limit to how far you can make your application go if you use lots of components from Zend Framework, but then there's also a limit for how fast your application can go before you need to drop PHP and write it in C. It's possible to make Zend Framework perform just fine on a high load site, but you have to put an effort in to it. Just like you have to if you don't use it.
This isn't a question about what framework to use. I've learned both Rails and Django, and I write all of my webapps in PHP. My question is why bother with the frameworks? It's always taken me longer to use a framework than to reuse old MySQL code and build "models" with phpMyAdmin. I also like writing everything myself, because I know what's going on. I can still reuse functions, etc. and do things how I want, and this freedom seems to be missing from most frameworks.
I'm not saying that my way is right; in fact, I'm trying to figure out where my logic fails. The hype can't be just thin air. What am I missing?
The basic idea of a framework is to allow you to work at a higher level of abstruction and write only the code you have to write to implement your specific requirements. All the other repetitive stuff is handled for you by the framework, and probably with far fewer bugs and security holes than if you did it yourself.
It may feel like it takes longer to learn a framework than to just do it yourself using basic language features and standard APIs, but it's simply not true - not if the framework is good and the app is non-trivial, and especially not once you have learned the framework (using a different one for each new project would of course be idiotic) and factor in the time it would take to find and eliminate all the bugs and correct all the design mistakes that have long since been found, eliminated and corrected in the framework by its developer community.
Almost every developer has cowboy coder instincts that tell him "Doing things yourself is much more fun than using code others have written, and I'm sure I'm good enough to get it right the first time, so it will even be faster and better!". These instincts are almost always wrong.
Frameworks allow you to concentrate on the application itself rather than worrying about the boilerplate code that you'd otherwise have to write for every application. They allow you to structure you site in a much more logical (mostly object-oriented) way, using tried and tested design patters such as model-view-controller. The code in framework is generally more mature and of a higher standard than code you would write yourself for one-off projects as framework have a large community of developers perfecting the code perfecting the code over year. This means that framework-driven sites often perform better and are much more secure.
You also mentioned you like writing things yourself - I know where you're coming from. My solution to this was to write my own framework - I get to reuse and improve my code with every project I do and I know the entire codebase inside out.
Writing it your self may make it easier for you to understand things your self but unfortunately it can make it much harder for other developers to understand what is happening. Frameworks will often be better documented and have a larger community that can support a new developer that is working on the app that you wrote.
I think a big part of it is what you focus on. Frameworks standardize the parts that you shouldn't have to keep revisiting, which helps you focus on the application as a whole. If you reuse your own code all the time you're already using your own makeshift framework.
Your comparing a framework (Rails) to a language (PHP). A framework is going to give you pre-built components so you can spend time on what makes your project unique.
You may already have a code base that helps do this for you. Check out some of the PHP frameworks since that's where you are more comfortable. Take a look at CakePHP, CodeIgnitor and/or Zend Framework.
If you are building many small apps/sites, using a framework may make your life easier.
I think a good step for you is to create your own framework with the code you've programmed so far. ;)
Try to make your code parametrizeable, in other words: create components which you can reuse in different parts of a website (for instance: styled containers), or in different websites (form generators/validators).
You can even go further and create base-classes from which you extend new classes to build your websites. (for instance: data objects with generic select/insert/update/delete methods).
I bet this gives you the best view on why frameworks are so damn handy ;)
It'll take you longer to initially use a framework for the same reasons a PHP developer would take longer to initially use Ruby - you're not familiar with it.
Once you're familiar with them, frameworks can offer the ability to skip the mundane and focus on actually writing the important parts of the app.
You should also just use a PHP based framework like Symfony or CakePHP using them should reduce your production time considerably.
One reason to use a frame work is code separation. Take symfony for example. The model is all done with propel or doctrine libraries. Very little SQL needed. You instantiate a new object and user getters and setters, to store your data, and instead of writing SQL in your page code you create functions in the objects related to the query. When you need to access the same kind of data on different pages you are asking the model for it, keeping the business logic with the model where it should be, so there's never any difference. All the work is done in the "action controller function". You get all the data you need, and then put as little php in the display, basically just echoing the variables you got in the action controller, (with the exception of some for loops and if statements for conditionals. I have found this a more efficient way to code, and on my 2nd project saw the production time cut in half.
You don't need to learn a new language python/ruby just to use a great framework, just have to fin one that works for you.
First, PHP has frameworks too, so the question as stated misses the point.
Yes, you can write your own framework, and as Kris said, there's no shame in that. However, part of the leverage of code reuse is the collective value of the efforts of many. It's not just about reusing your own code. Frameworks encapsulate the common tasks and patterns we all share and provide well tested solutions with many iterations of improvements from the community. No individual effort is going to measure up to that, no matter who you are.
If you roll your own, it will only become world class due to the collective effort of world class people, and that will only happen if your idea merits the attention. The top frameworks out there are already proven on those criteria.
DHH is a smart guy, but the Rails we have today never could have been realized by him alone. Not even close.
If you like "writing everything yourself" as you say, then choose a framework with a core philosophy that matches yours, and start making core contributions in the areas where you can see room for improvement.
Depending on the functions of your Web Application, it can be faster to develop without a framework. For example when the Webapp is just some kind of data viewer.
But as soon as you begin to implement more advanced functions, you are much more efficient with a framework.
Try do do this from scratch:
- proper Form validation
- Handling of multiple Language and Date/Time formatting
- Authentication
See a framework as free tools and stable implemented function for you to use.
Sounds to me like you have already written your own framework in php, since you do mention code reuse.
I can imagine it being easier to use your own set of wheels instead of adapting to someone else's. No shame in that.
Frameworks are there mainly to help people who are semi-new to PHP (or the specific language it is built on) to be able to build a website to an extent that it is secure and easy enough to add on extra parts to the site without having to know a lot about the specifics like security, MySQL (or other database types). In my opinion it is a fairly good way to help break coders into a language, allowing for the fact that the framework isn't too complex of course.
EDIT The reason behind me saying they are for beginners is because myself, as a beginner has used frameworks to break myself into languages a lot better.