Archive for December, 2006

Merry Christmas and Happy Holidays

Friday, December 22nd, 2006

I’m off for the long holdiay season, so I’ll be off blogging till the next year. So here’s wishing you all a Merry Christmas and a happy holiday season. In case I don’t come online till the next year, wish you a Happy New Year in advance. :)

Modifying your MySQL databases to be UTF-8 compliant

Friday, December 22nd, 2006

Most of us have had problems with UTF-8 problems in PHP and MySQL. Here’s how to modify your database and table to be UTF-8 compliant. Most of the time we do set the character set to utf8 but forget to set the collation set to utf8.

Use the following MySQL statements to convert your database and tables:

ALTER DATABASE mydatabase
CHARACTER SET utf8
DEFAULT CHARACTER SET utf8
COLLATE utf8_general_ci
DEFAULT COLLATE utf8_general_ci ;


ALTER TABLE mytable
DEFAULT CHARACTER SET utf8
COLLATE utf8_general_ci ;

Fluent Interfaces in PHP

Thursday, December 21st, 2006
A new buzzword in the PHP circles is Fluent Interfaces, which is not really new, but a way to chain methods of an object together. Here’s an example from Mike Naberezny which shows the regular way and the Fluent way:

< ?php private function makeNormal(Customer $customer) {
$o1 = new Order();
$customer->addOrder($o1);
$line1 = new OrderLine(6, Product::find(‘TAL’));
$o1->addLine($line1);
$line2 = new OrderLine(5, Product::find(‘HPK’));
$o1->addLine($line2);
$line3 = new OrderLine(3, Product::find(‘LGV’));
$o1->addLine($line3);
$line2->setSkippable(true);
$o1->setRush(true);
}
?>

The fluent way: < ?php private function makeFluent(Customer $customer) {
$customer->newOrder()
->with(6, ‘TAL’)
->with(5, ‘HPK’)->skippable()
->with(3, ‘LGV’)
->priorityRush();
}
?>

For those who do not recognize this particular buzzword fluent interfaces is a way of chaining methods of an object together. By having a method return a reference to the object itself, return $this; you chain methods together like this $this->methodOne()->methodTwo()->methodThree();. This can make your code easier to read, and that is the point of using fluent interfaces, making your code easier to read.

via: Zend Developer Zone

Andi Gutmans tells us where to use this pattern:

Of course there are no definitive answers but I suggest to consider the following points:
a) Use your intuition. If you don’t feel this will address the 95% of common use-case for using your interface, then it’s probably not the right solution for what you’re trying to accomplish.
b) As Paul noted, if in the common use-case you don’t have all the necessary data available to complete the task in one go, you should think twice about doing it.
c) Probably the most important point: It really has to read well in your language (e.g. English), preferably as a complete sentence. If you can’t read the code out aloud then it’s probably not what you want.

Link: Andi Gutmans’ Weblog | Fluent Interfaces

Mark Naberezny has an helloworld example at his blog which shows you how to build a fluent interface:

In PHP 5 terms, a fluent interface to an object is one where the setter methods return an object handle. It is perhaps simplest to always return $this, however any object handle can be returned. Here’s a simple PHP class that demonstrates how a fluent interface is built:

< ?php
class Fluent {
public function hello() {
echo ‘hello ‘;
return $this;
}
public function world() {
echo ‘world’;
return $this;
}
}
$fluent = new Fluent();
$fluent->hello()
->world();
?>

Link: Fluent Interfaces in PHP

debugConsole for PHP5

Wednesday, December 20th, 2006

debugConsoleI’m sure all us PHP developers have had to debug code on a production server and at the same time not have visitors to the site see our debug message on the site? Here’s a utility which gives you a the debug messages formatted neatly and allow locking down the debug messages only to a particular IP address so the debug messages are shown only to you and not visitors to your site.

This lets you leave your debug code on the site without having to add the debug code everytime you want to debug the application.

“With simple PHP functions you can inspect variables, watch changes in variables over the whole runtime, measure partial runtimes, set checkpoints and write logfiles. Additionally, the debugConsole replaces the PHP errorhandling so that notices, warnings and errors are shown in a popup too, instead of displaying them in the application to be debugged.”

Link: debugConsole

chabotc.nl » phpSocketDaemon

Tuesday, December 19th, 2006

Chris Chabot has released a new PHP package called phpSocketDaemon. This is a blazingly fast and easy to use to create daemons listening on a socket. Here’s some of the benchmarks on a httpd server created using phpSocketDaemon published by Chris himself:

Using apache bench (ab) on my home computer, using 256 concurrent , keep-alive requests over 50000 requests this server was able to serve over 4500(!) pages a second, and each page with a max latency of 0.15ms.

Download this package or get the latest svn code from
http://phpsocketdaemon.googlecode.com/svn/trunk/phpsocketdaemon

Project Page: http://code.google.com/p/phpsocketdaemon/

Link: chabotc.nl » phpSocketDaemon

Nuckin’ Futs - A Year in Review

Tuesday, December 19th, 2006

Just nucking cracked me up :)

Nuckin’ Futs! The JibJab Year in Review | Send To Friends | Funny Animations at JibJab

Cookie Theft on Shared Servers

Friday, December 15th, 2006

SecurityStefan shows how shared hosting environments could lead to security threat to your site, allowing another site on the same host to hijack cookies from your site.

Within a shared hosting environment it is sometimes quite often possible to bind yourself to some high TCP port and accept incoming connections. Sometimes this is possible because you also get a shell account on the box and sometimes because dangerous PHP functions like stream_socket_server() are not disabled in the configuration. Unfortunately the ability to bind yourself to a port and receive connections is a threat to webapplications installed on different virtual hosts on the same IP, even if other security measures in place, like tight filesystem permissions or executing PHP script with the permission of the owner.

Link: Cross Virtual Host Cookie Theft - PHP Security Blog

Getting started with Aptana and Yahoo UI - Aptana

Thursday, December 14th, 2006
Aptana

Want to create cool Web2.0 UI’s? You can use Apatana to create these using the Yahoo UI Library. Aptana provides you the IDE to create UI components with YUI and provides you with code complete facilities to do this too ! Check the link below to get started. Aptana also provides the same functionality for the following (”web 2.0“) libraries:

  • AFLAX
  • DOJO
  • JQuery
  • MochKit
  • Prototype
  • Rico
  • Scriptaculous

This walkthrough will instruct you how to create a new Yahoo UI library project and get started with your coding using the documented Yahoo UI library supplied by Aptana.

Getting started with Aptana and Yahoo UI - Aptana

PHP Upload Meter

Thursday, December 14th, 2006

Justin Silverton shows how to create an Upload Progress meter using PHP 5.2 and Yahoo User Interface. Prior to PHP 5.2, there’s no way a PHP script could monitor the progress of a file upload, causing programmers to look at Perl scripts to provide the same information. For a demo, head over to http://progphp.com/progress.php
This progess meter is based on the yahoo user interface library and alternative php cache (APC). You will need both of these for it to display properly. PHP 5.2.0 or higher is also required. (I have written a previous article on alternative PHP cache here). 

Jaslabs: High performance php » How to create a php upload progress meter

Network Scanning with HTTP without JavaScript

Friday, December 8th, 2006

Here’s a cool way to scan a site visitor’s network using just HTML and the user’s browser.
The concept of doing network scanning via JavaScript is hardly new and is quite easy for anyone with even cursory knowledge of JavaScript. However, the assumption was that as long as you browse the web with JavaScript disabled you are safe from hostile sites from scanning your network. Alas, this was not to be, in a very interesting post Jeremiah Grossman shows how can this be done with plain HTML using no JavaScript what so ever.

Link: Network Scanning with HTTP without JavaScript - iBlog - Ilia Alshanetsky

About Me

Here's my blog on stuff I keep finding on the Web. More

Want to subscribe?

 Subscribe in a reader Or, subscribe via email:
Enter your email address:  
On the Go? Get this on your Widsets: Add to my Widsets
Find entries :
Page 1 of 212»