I know this is my first post here, and I'm sorry that its asking rather than offering. Here it is anyway though. Thanks for your help.
I'm making an application, in all my experience with php(which isn't really all that much), I haven't used objects but once(and that was a very basic usage). For this application, which is primarily the backend for a facebook application, I've been writing a ton of functions, in ajax and php both( a ton == about 20 or so). Most of them are only run once, but some are run repetitively (about 10-50 times per session). Almost all of the functions are for Ajax Requests and database queries. Everything loads up into the primary page, with only one box loading content(and a status div that gets its innerHTML updated [for debugging mostly]).
I'm loading about 20k in files onload (not counting prototype[~180k total]).
Each request currently connects to the db. ( Worth using mysql_pconnect()? )
My question is primarily about efficiency, but there's a couple other ones.
Is it going to be a big (beneficial) difference in server load to switch it to objects?
Should I make an object/function to perform all of the requests dynamically?
Is there an all-in-one regex string that can make sure there isn't any xss submitted?
Thank you for your experienced opinions.
-Ri
Best approach.. Objects worthwhile?
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Best approach.. Objects worthwhile?
It can...but probably not. If you are really pedantic about object decomposition, keeping things simple, etc, you can certainly use objects too boost performance, but chances are, using objects will actually slow your application, although that loss in performance is moot as it's not visibly noticable for the most part.Is it going to be a big (beneficial) difference in server load to switch it to objects?
Not sure I follow you but going dynamic is usually the better approach when workin in PHP.Should I make an object/function to perform all of the requests dynamically?
No you could maybe use HTML_Purifier (Google it) to sanitize input or strip_tags if no HTML is allowed at all.Is there an all-in-one regex string that can make sure there isn't any xss submitted?
Re: Best approach.. Objects worthwhile?
No, it should be pluralized. One object should not handle all requests. One object should represent one single responsibility in the system, for instance one object could represent the request, and encapsulate acccess to your $_GET and $_POST variable. Each object in the system is a conceptual object you can think about, you don't want just one one big "Main" method, not the pointShould I make an object/function to perform all of the requests dynamically?
Re: Best approach.. Objects worthwhile?
Ahh thank you.
Good to hear that I don't need to remake everything.
I'm making progress but now having some trouble getting my php generated form to post via ajax.
The $_POST array just keeps appearing empty. :/
More details later if I can 't figure it out.
Good to hear that I don't need to remake everything.
I'm making progress but now having some trouble getting my php generated form to post via ajax.
The $_POST array just keeps appearing empty. :/
More details later if I can 't figure it out.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Best approach.. Objects worthwhile?
Not here, post it in the code section and make sure to add the PHP BB blocks around the code so it's colorized and easily read.
- PHPHorizons
- Forum Contributor
- Posts: 175
- Joined: Mon Sep 14, 2009 11:38 pm
Re: Best approach.. Objects worthwhile?
Pretty much all professional programmers are using object oriented programming. Probably none of them have discarded it because of it's increased overhead.
To put it another way, you would be hard pressed to find a professional programmer that will tell you to forgo using object oriented programming because of increased overhead.
The optimizations that really mean something on the web really fall into other categories. The big one is how much data you send over the wire. Next is probably how efficiently you utilize the database. Then it's a question of not nesting loops too deeply, and really making those loops efficient.
And if you're not on the web, and this is a desktop program, then efficiency is even less of a concern.
Hope that helps.
To put it another way, you would be hard pressed to find a professional programmer that will tell you to forgo using object oriented programming because of increased overhead.
The optimizations that really mean something on the web really fall into other categories. The big one is how much data you send over the wire. Next is probably how efficiently you utilize the database. Then it's a question of not nesting loops too deeply, and really making those loops efficient.
And if you're not on the web, and this is a desktop program, then efficiency is even less of a concern.
Hope that helps.