Archive for the ‘PHP’ Category

Some interesting Memcached readings

Friday, July 25th, 2008

Memcached internals

Memcached vs APC

Memcached as simple message queue

Use Gearman to avoid cache miss stampedes

Scaling memcached at Facebook

Remove new lines at the end of PHP scripts

Thursday, July 10th, 2008

New lines at the end of PHP files cause problems when including the file as you may not want this extra line.

For instance it messes up redirections in Myspace applications.

PDO cannot rewind or seek

Wednesday, July 9th, 2008

Basically it means you cannot retrieve one column at a time, as the first column you retrieve will move the pointer to the end of the data, and as you cannot rewind, the next call to retrieve the second column will return nothing, because you’re already at the end of the data.

Example:

$sql = "SELECT response, response_comment FROM responses";
$stmt = $dbHandle->prepare($sql);
$stmt->execute();
$stats = $stmt->fetchall(pdo::FETCH_COLUMN, 0);

Then if you proceed to fetch the second column… :

$stats = $stmt->fetchall(pdo::FETCH_COLUMN, 1);

… it will return nothing.

You would have to execute the query again before running a second fetchall().

If it had worked, it could have been used to get the 2 columns in 2 arrays, then run an array_combine() to get the columns of the first array as keys and the columns of the second array as values. Too bad.

Source

Protected vs Private variables in PHP

Monday, July 7th, 2008

Class variables in PHP come in different flavors:

Public: anyone either inside the class or outside can access them
Protected: only the specified class and subclasses can access them
Private: only the specified class can access them. Even subclasses will be denied access.

Load balancing on the cheap: DNS balancing

Thursday, July 3rd, 2008

So you can’t afford a F5 load balancer? But your Apache server is dying under the load?
We had to use load balancing using DNS because we had scaling issues. Fast and good fix (just add a box and one line of code).

Create different DNS entries for different front side Apache servers:
www1.example.com
www2.example.com
www3.example.com

And in your code (PHP):

$baserUrl = "www".rand(1,3).".example.com";

Source