Stefano Posted December 30, 2010 Share Posted December 30, 2010 Hi everyone, I just joined this forum and I hope you can help me with my problem. I've been messing around with php for a while, building websites with frameworks and recently i decided to write my own framework. I got it done pretty quickly and it works fine but i'm starting to think that maybe MVC isn't the best design choice for a webapp. My main concern is speed, my code right now is quite clean and mantainable but there are a few problems. I redirect every request to index.php using an .htaccess file (and i think that slows down my site) and also i'm using url routing, so for each request to the server my code will loop over all the regexps and check if he can find a match... Oh and... then i load the controller wich loads the models and view etc.. etc.. I think all those operations slow down the website a lot and I would like to know if you have any solutions to my problem, my english is pretty bad I know, I hope you'll understand what i wrote anyway Edit: I'm also considering the idea of writing only procedural php from now on, i want superfast websites. The code will probably be hard to mantain but as i said, all i want is speed, what do you think? Quote Link to comment https://forums.phpfreaks.com/topic/223039-mvc-and-speed/ Share on other sites More sharing options...
trq Posted December 30, 2010 Share Posted December 30, 2010 I redirect every request to index.php using an .htaccess file Are you sure? A redirect would be time consuming, but that's not the typical method. Typically you just tell the server to pass all requests to an index.php file. This costs no time at all. Routing can be an expensive operation in most MVC's that I've seen. This really is the part of the application that needs allot of optimization, and youv'e just got to be careful how you go about things. We would need to see some relevant code before we could understand exactly how your routing works and be able to offer much assistance. Though there are a few pointers we can probably through at you. Avoid routing via regex where possible. If you don't need to match a pattern, and can simply match a static url to a controller / action, then do so. Put your simplest routes first. This way you don't have to waste time processing the more complex ones unless they are needed. That's probably all I could offer without seeing your code. Quote Link to comment https://forums.phpfreaks.com/topic/223039-mvc-and-speed/#findComment-1153164 Share on other sites More sharing options...
Stefano Posted December 30, 2010 Author Share Posted December 30, 2010 Thank you for your reply, I can surely optimize routing, remove the htaccess and let the server handle that but is the design wrong? OOP in general, it's clean and maintainable but also much slower than procedural... but i'm not sure if i'll be able to handle a big project using procedural programming... it's really hard to choose... Edit: what i really wanted to ask is: if you gotta write Youtube, what would you use? OOP+MVC? Procedural? i'm not writing youtube but it's just an example, i want to make the fastest possible website wich is also possible to maintain... hard choice Quote Link to comment https://forums.phpfreaks.com/topic/223039-mvc-and-speed/#findComment-1153172 Share on other sites More sharing options...
trq Posted December 30, 2010 Share Posted December 30, 2010 I can surely optimize routing, remove the htaccess and let the server handle that The .htaccess file is a server config file. So you are letting the server handle it already. If your application is noticeably slow your likely doing something wrong somewhere or over complicating things. The MVC pattern lends itself very well to web applications, hence it's popularity. I've written a couple of frameworks in my time (all have since been superseded by the next and I'm currently in the process of again another complete rewrite) but have never had any issues with speed. Most of my issues are maintainability, but that's just because I can have a tendency to over complicate things. Try and keep your design as simple as possible (KISS). Quote Link to comment https://forums.phpfreaks.com/topic/223039-mvc-and-speed/#findComment-1153181 Share on other sites More sharing options...
Stefano Posted December 30, 2010 Author Share Posted December 30, 2010 I know that .htaccess overrides the server configuration but it's good to remove it and instead edit the server configuration file, i heard it's faster that way. My application is not slow, but i think it would be very slow if i had a lot of users online, and hm yea i think i tend to over complicate things too Quote Link to comment https://forums.phpfreaks.com/topic/223039-mvc-and-speed/#findComment-1153191 Share on other sites More sharing options...
Anti-Moronic Posted January 1, 2011 Share Posted January 1, 2011 Stop fixating on .htaccess. That is so trivial compared to what thorpe mentioned it's not even worth thinking about. Pass all queries through the index.php file and go from there. Stop worrying about .htaccess. Oh, and no I wouldn't advise trying to find an alternative to using an app specific .htaccess. You want your code to be somewhat portable too. Editing server configuration files is host-dependent. mod_rewrite is largely supported and enabled. I haven't written any MVC-based frameworks so can't advise on that but I can tell you along with optimizing your code, you will want to look into caching. You should also note the major bottleneck in most web apps is the database so focus on optimizing that. Quote Link to comment https://forums.phpfreaks.com/topic/223039-mvc-and-speed/#findComment-1153495 Share on other sites More sharing options...
ignace Posted January 1, 2011 Share Posted January 1, 2011 I redirect every request to index.php using an .htaccess file (and i think that slows down my site) Like Anti-Moronic already mentioned it isn't. Plus it has nothing to do with OOP i'm using url routing, so for each request to the server my code will loop over all the regexps and check if he can find a match... RegEx are slow, the manual advises to use normal string functions before moving to RegEx. Again has nothing to do with OOP. What are the URI's in your app? If you don't have many URI's you may aswell just store them in an array: /* $route[ {REQUEST_URI} ] = array( {CONTROLLER}[, {METHOD}[, {PARAM}, .. ] ] ); */ $route['/about'] = array('about', 'index'); $route['/jobs'] = array('about', 'jobs'); Quote Link to comment https://forums.phpfreaks.com/topic/223039-mvc-and-speed/#findComment-1153516 Share on other sites More sharing options...
Stefano Posted January 1, 2011 Author Share Posted January 1, 2011 Thanks for your help, I was thinking about cache and I think i will build a database query cache system, so that you execute queries only once an hour or something like that, because query results would be cached i think that would be pretty cool, also i could cache anything else basically... for the htaccess, probably i'm too worried about that, and hm... for url routing i'll test a few things and i'll update you Still... OOP looks kinda slow to me, and PHP has a garbage collector, so it's even worse speed-wise. But yea... i'll probably use it anyway, takes too much time to write and maintain procedural code. And as i said, i'll be using cache so i'll be fine with OOP. I think i'll just post some code later, so we can optimize it, if you are nerd enough Quote Link to comment https://forums.phpfreaks.com/topic/223039-mvc-and-speed/#findComment-1153618 Share on other sites More sharing options...
Anti-Moronic Posted January 2, 2011 Share Posted January 2, 2011 Without speaking for everybody else, we are all nerd enough; every one of us. Quote Link to comment https://forums.phpfreaks.com/topic/223039-mvc-and-speed/#findComment-1153753 Share on other sites More sharing options...
ignace Posted January 2, 2011 Share Posted January 2, 2011 OOP looks kinda slow to me, and PHP has a garbage collector When it comes to garbage collection OOP is your friend, every-time your code exits a method or you set $class = null it's garbage collected, the same applies for a function. Where as if you have a page with all your code it's only garbage collected at the end of your script or if you called unset() so it's wise to put as much code into functions. takes too much time to write and maintain procedural code There's a topic on this forum about OOP vs Procedural in which I and Anti-Moronic among others have actively participated Their are lots of open-source procedural projects that proof to be maintainable like: PHP, MySQL, Linux, Apache, .. so it all boils down to how you generally organize things. Without speaking for everybody else, we are all nerd enough; every one of us. Yup. We are all certified: 99% nerd inside. Quote Link to comment https://forums.phpfreaks.com/topic/223039-mvc-and-speed/#findComment-1153799 Share on other sites More sharing options...
Stefano Posted January 2, 2011 Author Share Posted January 2, 2011 Ok guys i made a topic with the code: http://www.phpfreaks.com/forums/php-coding-help/omega-framework/ It currently sucks, but i'll work on it! Obviously feel free to give suggestions and/or rewrite some of the code, <3 Quote Link to comment https://forums.phpfreaks.com/topic/223039-mvc-and-speed/#findComment-1153967 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.