Archive Page 2
Well the code for facebooks index page has been leaked and I had a chance to look it over. I was curious as I develop in PHP on enterprise level apps and wanted to see how they do their code. Here are my few impressions:
Pros:
They use templates, That is always a good thing, it separates code from HTML.
Its clean, you can tell they use coding standards.
Cons:
Little evidence of OOP (Object Orientated Programming.)
The link to the code has been taken down with Facebook slapping a cease and desist on the blogger. But if your still curios you can find screen shots at http://bayimg.com/lAFLaaAbl
Well I was asked if I could out content in a window that was scrollable without using an iframe. I personally dislike iframes so I was happy to oblige. Its actually quite a simple task when you get down to it, so lets get started.
1. Create your div.
<div>Paragraph or two of text here….</div>
2. Add the styles to the div.
<div style=”overflow:auto; width:200px; height:200px;”>Paragraph or two of text here….</div>
If you’re using a linked stylesheet or defining it in the header you would use this CSS:
div.scrollable {
width: 200px;
height: 200px;
overflow: auto;
}
The following methods can help improve scalability with php applications.
1. object code caching
Whenever a request comes in for a php script, it has to go through the compiler and then execute the object code. If this is cached, you skip compiling and go straight to executing, hence a speed increase
There are quite a few object code caching packages, some are free and some are not:
A) Ioncube: http://www.ioncube.com/
B) Zend Encoder: http://www.zend.com/products/zend_safeguard (Not Bad)
C) Turckl MMCache: http://freshmeat.net/projects/turck-mmcache/ (My Fav)
1. Templating systems
Templating systems provide a different type of caching. HTML caching. Templating systems work well when you have static data on one or many of your pages that doesn’t need to be reloaded often. Caching systems also provide a separation of code and html, simplifying the system and making future additions or upgrades easier.
A) Smarty Templates: http://smarty.php.net/ (MY fav)
B) Pear Templates: http://pear.php.net/package/html_template_it/redirected
3. Distributed object caching systems
The most widely used system of this type is memcached (http://www.danga.com/memcached/).
This type of caching makes your database querying faster by caching the majority of your database queries.
4. PHP variables that can be set
variables_order = ‘GPC’
register_argc_argv = ‘Off’
register_globals = ‘Off’ (this is a good idea to keep off for security purposes as well)
always_populate_raw_post_data = ‘Off’
magic_quotes_gpc = ‘Off’
Use IP address to access your database. Do this as much as possible as you save the hostname lookup time..
5. Output Compression
Most current browsers now support gzip compression. Gzip compression can decrease the overall size of your output by up to 80%, but with a tradeoff: cpu usage will go up by around 10%. This will actually compress your HTML output befor sending to the browser, decreasing your bandwdth usage and speeding up the page loading.
add the following lines to php.ini to enable:
zlib.output_compression = On
zlib.output_compression_level = (level) (where level is 1-9. Youy may want to try different values to see what is best for your system).
if you are using apache, you can also enable the mod_gzip module. It is highly configurable, with the ability to modify output based on MIME types, files, or browser settings.
6. Optimize your database and queries.
Query only what you need, avoid SELECTING * and please, please, please index your tables!
I know there are web developers out there that know squat about JavaScript. I know, I am one of them, I mean I can write something if I really have to but most things you need done with JavaScript you can find someone who has written a script, reference, library, framework that already does it….So that leaves most web developers more concerned with the server side scripting languages. Anyway I ran across a great framework for PHP programmers, QuTags, it does most of the work for you and is handy in a pinch. Has some great tutorials on their site and you can even get this as an apache C mod. Check it out.
http://www.ajaxforphp.com/qutags/
You ever programming and need some reference material? I know when I do it is sometimes hard to find teh exact info you need, maybe its not in one of your cheat sheets, or its one of those obscure once a decade things you need to find. I know I run across those type of references all too often. Usally when I get some harebrained idea, that wont really work, but your still driven to make it work. Well here is a nice all in one searchable reference. Its not perfect, but it has helped me out a few times.
For those of us, lucky enough to be Linux Sys admins, Network admin, App Programmer and Tech support, you sometimes need some help. I keep cheet sheets on hand for every app, network appliance, box, system or peice of junk just so I can get the job done without loosing my mind. In my repertoire of cheat sheets in teh all purpose linux cheat sheet that I refer to when I don’t know or can’t think straight. Its handy and will help with most distros.
You know when your programming in PERL or PHP and you just can’t think of that corresponding function? Well ease your mind. I have found a list that pairs them off and makes translating, either way, an much easier task. This list is great even if your not trying to translate from one to the other, its just handy to look up functions while your coding.