How to optimize PHP performance with the APC Cache

I highly suggest using the APC cache on your PHP installation. Here are instructions for installing APC on Debian Etch. The package exists on Debian Lenny.

With no extra work by the programmer, APC begins creating pre-interpreted (opcode) caches of your most run PHP files and keeping them in memory. When requests come through, many common classes no longer need to be loaded from the hard disk and interpreted. 

The speed improvements on my server was visible.

MySQL Timestamp Column Properties for Auto Initialization and Update

I always forget the syntax for MySQL Timestamp Properties:

The following column definitions demonstrate each of the possibilities:

  • Auto-initialization and auto-update:

    ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    
  • Auto-initialization only:

    ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    
  • Auto-update only:

    ts TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP
    
  • Neither:

    ts TIMESTAMP DEFAULT 0

Tip: str_replace_once() i.e. str_replace once or one occurrence

This is the right way to do it, with strpos and substr_replace:
str_replace() .... only once occurence only....
I changed strpos to stripos for case insensitive use

How to Parse a URL to a base domain name in PHP

Here's a very simple function called stripit to reduce a url to a base domain:

e.g.

http://mail.google.co.uk  to google.co.uk 

http://www.google.com  to google.com 

Nice function to get final redirect - ed URL in PHP e.g. handling feedburner or proxy urls

Well written function helper for getting the final redirected URL of a link

e.g. Convert

http://feeds.feedburner.com/~r/rawstory/gKpz/~3/426580476/Google_CEO_to_endorse_Obama_WSJ_10202008.html

to 

http://rawstory.com/news/afp/Google_CEO_to_endorse_Obama_WSJ_10202008.html


Jing is proving very helpful

I really like Jing, it's a handy screen capture and video recording widget. It makes sharing clips from my screen with colleagues about as easy as I could imagine. It's nice to see simple products that simplify tasks in a straightforward, elegant way. Maybe Jing could make me a to do list app!

Saw it first from @phillipadsmith

CSS Tip: How to Style a Tag Cloud - Use CSS to Generate a Tag Cloud on Your Site

This is a pretty simple, straightforward tag cloud CSS implementation:

Facebook FBJS Ajax Tip - There is no URIEncode in FBJS

Just a handy reminder when using FBJS Ajax: If you need to send a string that would normally be encoded via FBJS Ajax, you should use the queryParams variable...that will encode the data for you. 


However, please note that the variables you receive on the AJAX server side will be in POST not GET.

For example...

var ajax = new Ajax();
var queryParams = { "qStr" : val };
ajax.responseType = Ajax.FBML;
ajax.requireLogin = false;
    ajax.ondone = function(data) {panel.setInnerFBML(data); };
ajax.post(ajaxUrl+"?p=ajax&m=yourFunction",queryParams);

The PHP on the AJAX server side should be:
$qStr=$_POST['qStr'];


Three Benefits for Web Applications Developing inside Facebook

As Facebook has grown to over two hundred million users, they've done an extremely good job preventing spammers from creating fake accounts and harassing members. As you create a new Facebook account, they require a number of captcha's and checks to make sure the person is real and has real friends.

Facebook accounts are essentially a white list of users that have been incrementally vetted by the service and their real world friends. It's much harder to create a number of fake Facebook accounts than it is to create fake email accounts on a service like gmail or yahoo. 

As a result, when you run a Facebook application, you gain a few key side benefits that I think are unique to the Web right now:

1) Less spam and e-marketing

On a normal Website, people register with email addresses that don't provide the website operator with very much information about them. New accounts can easily post spam and marketing links to your site. With Facebook applications, this rarely happens.

I see far more spam and e-marketing on NewsCloud.com's website than on our Facebook-based news community applications e.g. Hot Dish and MnDaily.

2) More civilized dialogue; less abuse

Facebook's built-in social accountability leads to higher quality content and less undesired remarks. Because Facebook comments are often re-published to the Facebook stream which is seen by the member's friends, they are more accountable to their own real world social network for what they say.

Furthermore, Facebook comments are published with user's real names (see below), not handles that conceal their identity.

With our Facebook news community applications, I'm seen almost no abuse.

3) Good enough authentication

When a Facebook member with 100+ friends arrives at my Facebook application community, I can be pretty certain they are who they say they are. As Facebook members confirm more friends on their account, you can be incrementally more sure.

This just isn't the case with a typical Web registrant with a gmail or Yahoo email account.

While this isn't sufficient on its own for e-commerce, it's pretty good for the purpose of most Web-driven communities. e.g. showing a leaderboard of members to our community

In Closing

Theoretically, you could also gain these benefits by using Facebook Connect on your website or by implementing a tiered registration system which streamlined activity permissions for Facebook Connect registrants.

You can learn more about our Facebook news community applications here.

Backing Up and Restoring Your MySQL Database

This is a handy guide to backing up and restoring your MySQL database using mysqldump:
Backing Up and Restoring Your MySQL Database