Archive for September, 2008

directorycritic.com list of directories sucks

Those of you who know about SEO know that one of the easy ways to promote your site and show to search engine that your site exists is to submit your site to directories.

I submit my sites to a few directories every once in a while and I used to use directorycritic.com’s free list of directories.

Lately, there are so many junk directories listed that you can not believe, they are death, paid or their submit form doesn’t work.

I don’t know why this happened but I’m guessing that the owner paid someone to take care of his site for him and that someone is either dishonest or very lazy to the point that the list is almost not usable and a waste of time.

If you know about directories, you know that 90% of them are lame to begin with, the owners setup those directories with free scripts, templates and no technical knowledge.

Here are some of the stupid things about many of these directories:
1 - They have funny and irrelevant domain names.
2 - They have funny and irrelevant names.
3 - Their submit forms don’t work.
4 - Their submit form does work but it doesn’t tell you that if your submission was successful.
5 - Their Captcha image doesn’t work.
6 - They use bad English. (worst than mine :))
7 - They never approve any link, some of them have 1,000s of links waiting for review.

Archived under Annoying Stuff, SEO Comments

PHPCache, a simple, powerful object caching solution for PHP applications…

[ D O W N L O A D ]

If you have a dynamic website, written in PHP and your site is slow then this solution might help you.
Some times you have to have some nasty query then process the result afterwards which makes the whole thing even nastier and slow.

With PHPCache, you will be able to cache the result of that piece of code for as long as you want.
Suppose that your nasty script gets 100 hits per second, and you cache your script using PHPCache for just 1 minute at a time, the result is, in that one minute your server will run that piece of code only once.

PHPCache will only query the database for the result that was stored in the database 100 times in that one minute.
This will be a very quick process, since it’s only a primary key lookup (piece a cake) for MySQL and SQLite. These databases can handle 1000s of simple queries like these per second! But your server might only be able to process your code 5 times per second…
In fact I tested this and SQLite could retrieve the cache 2,300 per second, MySQL around 2,500 times!

PHPCache supports MySQL, MySQLi and SQLite extensions at this time but you are welcome to write and submit extensions for other database servers.

The other great thing about PHPCache is support for SQLite; SQLite is a very nice, quick little database that you can setup easily and you won’t need to have MySQL.

Here is an example usage of PHPCache:

require_once 'phpcache.class.php';
 
	$database = array(
		'type'  => 'mysql',
		'name'  => 'YOUR DATABASE NAME',
		'table' => 'PHPCache',
		'user'  => 'YOUR DATABASE USERNAME',
		'pass'  => 'YOUR DATABASE USERNAME\'S PASSWORD',
		'host'  => 'localhost' /* Or maybe IP address of your database server */
	);
 
	PHPCache::configure($database);
	$cache = PHPCache::instance();
 
	if( ($results = $cache->get('result_of_some_nasty_code')) !== false ) {
		$tpl->assign($results);
		/* Or maybe return $results or whatever depending on where you use this */
	} else {
		/***********************
		 * Your slow code here
		 ***********************/
 
		$cache->store('result_of_some_nasty_code', $results_of_your_slow_code, PHPCACHE_1_HOUR * 5); /* Cache for 5 hours */
	}

It’s very simple!

You can use it in any kind of application, commercial and non-commercial, the only thing I ask is that if you like it, help me spread the word.
You can write a blog post about it, tell your friends about it or whatever, I will really appreciate that :)

What you can store
You can store variables, arrays and objects BUT not resources (like a file or a database handle), PHPCache will serialize your array or object for you but remember to read the information on this page regarding object unserialization:
http://us3.php.net/unserialize

Date constants
PHPCACHE_1_SECOND
PHPCACHE_1_MINUTE
PHPCACHE_1_HOUR
PHPCACHE_1_DAY
PHPCACHE_1_WEEK
PHPCACHE_1_MONTH
PHPCACHE_1_YEAR

To store something for 5 days:

$cache->store('user_' .$user_id, $results_of_your_slow_code, PHPCACHE_1_DAY * 5);

How fast is it?
It can handle 2,300 queries per second on SQLite and 2,500 on MySQL. That’s very fast…

What about user specific data?
If your website has members and you want to cache some data specific to a user you can do something like this:

$cache->store('user_' .$user_id, $results_of_your_slow_code, PHPCACHE_1_MINUTE * 5);

What about the database table?
You don’t need to create the database table for PHPCache, the only thing you need to do is to populate this array:

$database = array(
		'type'  => 'mysql',
		'name'  => 'YOUR DATABASE NAME',
		'table' => 'PHPCache',
		'user'  => 'YOUR DATABASE USERNAME',
		'pass'  => 'YOUR DATABASE USERNAME\'S PASSWORD',
		'host'  => 'localhost' /* Or maybe IP address of your database server */
	);

Or for SQLite:

$database = array(
		'type'  => 'sqlite',
		'name'  => 'PATH TO A DATABASE FILE',
		'table' => 'PHPCache'
	);

“The filename (which is the name in our $database array) of the SQLite database. If the file does not exist, SQLite will attempt to create it. PHP must have write permissions to the file if data is inserted, the database schema is modified or to create the database if it does not exist.”

You can read more about SQLite here:
http://us3.php.net/manual/en/book.sqlite.php

After you setup the $database array you can go ahead and configure PHPCache like this:

PHPCache::configure($database);

Then you can ask PHPCache to make the table for you:

$cache = PHPCache::instance();
$cache->create_table();

Remeber to call $cache->create_table(); only once the first time you use PHPCache!

Also remember, when using SQLite, PHP must have write permissions to the directory you want to make the database file in, for example if you have:

$database = array(
		'type'  => 'sqlite',
		'name'  => $_SERVER['DOCUMENT_ROOT'] .'/cache/phpcache_database_file',
		'table' => 'PHPCache'
	);

You must create the directory “cache” and change it’s permissions so PHP can write to it.

How to write a driver for it?
Here is the interface your driver should implement:

interface PHPCache_Driver_Interface {
 
		public function query($query);
		public function escape($value);
		public function close();
		public function error();
		public function create_table($table_name);
 
	}
 
 
	interface PHPCache_Driver_Results_Interface {
 
		public function fetch_row();
		public function fetch_array();
		public function fetch_assoc();
 
	}

Suppose you want to write a driver for MSSQL, then you will have to write two classes and place them in a file named “phpcache.driver.mssql.class.php” and move it to the folder “PHPCache/drivers”.

Your class names should follow these rules:

             class PHPCache_Driver_mssql implements PHPCache_Driver_Interface {
                  /* ... */
	} // Class
 
 
	class PHPCache_Driver_mssql_Results implements PHPCache_Driver_Results_Interface {
	    /* ... */
	} // Class

Then you can use your driver like this:

$database = array(
		'type'  => 'mssql',
		'name'  => 'YOUR DATABASE NAME',
		'table' => 'PHPCache',
		'user'  => 'YOUR DATABASE USERNAME',
		'pass'  => 'YOUR DATABASE USERNAME\'S PASSWORD',
		'host'  => 'localhost' /* Or maybe IP address of your database server */
	);

Take a look at one of the drivers to see how exactly it looks like.

EDIT 9/15/2008:

A new version of PHPCache is available.

This one has 5 new methods:

PHPCache::set_expire($key)
Which will set the expiration of the cache record for $key in the past, I think this method has some advantages over deleting the key all together.

PHPCache::remove($key)
Will completely remove the row.

PHPCache::clean_up()
This method will be called when ever you construct/configure a new PHPCache object with PHPCache::configure($database) method and does two things:

1 - Will delete all the old keys on the table, you can control how often this happens with 2 constants:
PHPCACHE_GC_PROBABILITY & PHPCACHE_GC_DIVISOR
If you set PHPCACHE_GC_PROBABILITY to 10 and PHPCACHE_GC_DIVISOR to 100, then when ever you configure the PHPCache object with PHPCache::configure($database); there will be 10% chance that the garbage collector will delete the old rows.
The default value is 1%.

2 - It will optimize the table PHPCache is using, you can also control how often this happens through 2 other constants:
PHPCACHE_TO_PROBABILITY & PHPCACHE_TO_DIVISOR
It works similar to #1 and default value is 10%.

PHPCache::gc()
Will delete the old rows anytime you call this method, it doesn’t care about PHPCACHE_GC_PROBABILITY & PHPCACHE_GC_DIVISOR
One place to use this would be a cron tab.

PHPCache::optimize_table()
Will optimize PHPCache’s table and doesn’t care about
PHPCACHE_TO_PROBABILITY & PHPCACHE_TO_DIVISOR

This new version has some more minor improvements over the old one too.

Archived under PHP, Server Performance, Web Development Comments (5)

Cutest picture of Nou, my daughter

Archived under Fun, General Comments (2)

So I’m learning another programming language called Scheme

Scheme is a dialect of LISP and it’s supports functional paradigm.

In Scheme, everything is a list and you can for example sum all the elements in a list like:

(+ 1 2 3 4 5)

The above example will be evaluated to 15.

It’s a fun little language and can be very challenging sometimes which makes it more fun.
You can download an implementation of Scheme called Kawa here:
http://www.gnu.org/software/kawa/

I will write about it more soon.

Archived under Scheme Comments

highscalability.com and some funny comments they make

1-
One of them which is posted on: (Until now at least 9/4/2008)
http://highscalability.com/digg-architecture

In the “Lessons Learned” section says:
Tune MySQL through your database engine selection. Use InnoDB when you need transactions and MyISAM when you don’t. For example, transactional tables on the master can use MyISAM for read-only slaves.

InnoDB tables are mostly faster than MyISAM. The only thing MyISAM supports is full-text search which is crappy and slow on large datasets anyway.

2-
On the same page:
They moved nearly all work out of the database and into applications, including joins, an operation we normally think of as the job of the database.

a) If you want to join tables from your PHP scripts, that means putting a query in a loop and that means sending a query 10, 15 or 20 times to MySQL and get the results and put the results together some how.
This is slow your application down dramatically…
On the other hand, you can let MySQL handle; MySQL is written in C which is a lot (I mean a lot) faster than PHP; it is also designed to do joins and things like that and knows how to optimize your joins; it is made to be fast!
(This also applies to most database servers)

b) If you want to move sorts to PHP, then you are in so much trouble, say you have 1,000,000 users in a table and you want to get your latest 10 users sorted by username, do you know what you have to do?
You have to load all 1,000,000 users to an array in PHP and then use a usort with a custom function that compares the usernames and the problem with this is that PHP will probably run out of memory in the first place and if not, it will take a long time.

If you follow these 2 “lessons” you will make web applications that suck so bad that you either have to rewrite them or add 1 server per 10 extra users per second…

Archived under Annoying Stuff, Server Performance, Web Development Comments

Acid Test and different web browsers

Acid test is a test to identify problems web browsers have when rendering web pages.
There are 3 versions Acid Test 1, 2 and 3.

Acid2 should look like this:

But here is how Acid Test 2 works on my different browsers:

Google Chrome:

Firefox:

Opera:

Safari:

Retarded Internet Explorer 7:

!!!

Now, none of my browsers passed Acid Test 3!!!
It should look like this:

Google Chrome:

Firefox:

Opera:

Safari:

Retarded Internet Explorer 7:

Of all the browsers, all perform almost the same but only Internet Explorer is way off, I don’t know what the developer team who is in charge of Internet Explorer does at Microsoft every day. I’d say all of them deserve to be fired!!!

Of all the other browsers, I think Apple Webkit rendering engine is the best (Google Chrome and Apple Safari) which I think is another reason for Google to use it in their browser Chrome.

Apple Webkit is a state of the art and open source HTML rendering engine developed and released by Apple.

Here are the links to these tests:
Acid2
Acid3

Archived under CSS, HTML, Web Browsers, Web Design, Web Development Comments

My first impressions of Google Chrome

1 - It was extremely easy to install.
2 - It looks like a solid product.
3 - It doesn’t crash like IE 8.
4 - It’s fast.
5 - It’s very smooth.
6 - Has spell checking built in. (Just right click on the words that are underlined…)
7 - It’s very simple and elegant looking.
8 - Has nice new JavaScript engine V8.
9 - Has a nice JavaScript console and debugger.
10 - It doesn’t take 3 seconds (15 million instruction) to open a new tab.
11 - When you right click on a link it says “Copy link address” not “Copy shortcut” ;)

I’m using Google Chrome to write this and it might be the end of IE horror for me :) (and yes I don’t like Firefox…)

I also noticed that Cnet news wrote this funny article:
http://news.cnet.com/8301-17939_109-10030522-2.html

In case the author doesn’t know (which I think they should, before they write for Cnet) that is Google’s general terms of services and applies to all of their products including Gmail:
https://www.google.com/accounts/TOS?loc=US&hl=en

Archived under Web Browsers, Web Design, Web Development Comments

Google Chrome; another browser for your browser arsenal!

Now you can download a beta version here:

http://www.google.com/chrome/

I make web pages so I have to have all the possible browsers installed so I can check the pages I code in all of them and make sure they look the same.
So far I have Internet Explorer 7, Internet Explorer 6, Firefox, Opera, Safari and now Google Chrome!

It was a really easy and smooth installation and it even automatically imported my favourites from Internet Explorer.

Archived under Web Browsers, Web Design, Web Development Comments

Users without JavaScript and what to do about them

Here is what I do:

<noscript>
	<div style="color:#FF0000">
   	<strong>Sorry!</strong><br /><br />
      Please enable JavaScript on your browser to be able to use advanced features of this site.
      <br /><br /><br />
      <strong>Internet Explorer 6 or 7</strong>
      <ul style="list-style-type: decimal">
      	<li>Click the Tools menu.</li>
         <li>Select Internet Options.</li>
         <li>Click the Security tab.</li>
         <li>Click the Custom Level button.</li>
         <li>Scroll down until you see the 'Scripting' section. Select the 'Enable' radio button for 'Active Scripting.'</li>
         <li>Click the OK button.</li>
         <li>Click the Yes button in the confirmation window.</li>
      </ul><br />
      <strong>Firefox 2 or 3</strong>
      <ul style="list-style-type: decimal">
      	<li>Click the Tools menu.</li>
         <li>Select Options.</li>
         <li>Click the Contents tab.</li>
         <li>Select the 'Enable JavaScript' checkbox.</li>
         <li>Click the OK button.</li>
      </ul><br />
      <strong>Safari 2 or 3</strong>
      <ul style="list-style-type: decimal">
      	<li>Click the Safari menu.</li>
         <li>Select Preferences.</li>
         <li>Click the Security tab.</li>
         <li>Select the 'Enable JavaScript' checkbox.</li>
      </ul>
   </div>
</noscript>

“noscript” tag ensures that users without JavaScript will see this message ;)

Archived under AJAX, JavaScript, Web Development Comments

Programming Paradigms 6; Stack

Prof. Cain discusses C language programming by focusing on different forms of stack.

Archived under Assembly Programming, C Programming Comments

Google Chrome!

Google was working on an open source browser called Chrome!!!
http://googleblog.blogspot.com/2008/09/fresh-take-on-browser.html

Archived under Web Browsers Comments

jEditable and password input type support

I wrote a post earlier about how jEditable (a jQuery) plugin needed password support and the author of the plugin wrote back and said here is how to add this feature:

$.editable.addInputType(’password’, {});

You can read more here:
http://www.appelsiini.net/2007/8/custom-input-types
http://www.appelsiini.net/2008/4/autogrow-textarea-for-jeditable

This plugin is really great and we are doing some exciting things on Bloggapedia with it.
We will launch early this week hopefully because we are working on a recommendation engine.

Happy Coding :)

Archived under AJAX, JavaScript, Projects, Web Development Comments

Next entries »