Phine Solutions web work notes

PHP output compression

Filed under: PHP development by 1.618 — October 31, 2006 9:20 pm

In php.ini file

zlib.output_compression=On
zlib.output_compression_level=5

If you use ob_start() (output buffering)Â in php script:

use ob_start(‘ob_gzhandler‘);

Using both will not get the output compressed twice ;) , there will be an error reporting confliction instead.

environment setup – change shell

Filed under: web site hosting by 1.618 — October 29, 2006 9:33 am

Whenever you get a new *nix environment the shell you are offered to use may not be the one you like.

To change the default login shell is pretty simple:

first, check the available shells in the system:

more /etc/shells

Output:

/bin/sh
/bin/csh
/bin/tcsh
/usr/local/bin/tcsh
/usr/local/bin/bash
/usr/local/bin/fdsh
/usr/local/bin/ksh

second, use chsh command

chsh -s /usr/local/bin/ksh

This should do it.

If your system has bash, which is my favorate, you will also need to create .bash_profile and .bashrc for the alias, promot etc… settings.

A sample .bashrc can be found here.

Â

A good place to learn multi-column page design using css

Filed under: web 2.0 build 1 by 1.618 — October 23, 2006 10:22 am

I found this link from the sitepoint forum that explains how to use css to design the multi-column layout page.

CSS multi-column layoutÂ

It’s very comprehensive and definitely a great reference.

IE7

Filed under: my 2 cents by 1.618 — October 22, 2006 10:09 pm

Installed IE7 over the weekend and gave it a spin. I have to say I was pretty impressed. It looks like IE7 has borrowed some design concept from Opera, which is giving the user more room for the web page, and minimize the occupation of the menus and toolbars as much as possible. This is what I like the most. I tried to install an add-on, but got as far as to the point of downloading it, when I see it is an seperate intallation program I ducked. For a moment the "phishing filter" tool caught my eyes. It checks MS's database to see if the website you are visiting is black listed. I wonder how good can� MS keep their database updated. Overall I like the new IE7, but I wonder if it is designed too much toward the technical savvy crowd, regular users may need to take time to cacth on. As far as the security concern, what's new? IE has its foundamental flow and so many really smart people try to crack into it, so don't be surprised to see them coming.

PHP caching

Filed under: PHP development by 1.618 — October 18, 2006 8:33 pm

I started to implement the PHP caching for one of my site. Since I use PHP/Smarty, there are a few options.

Smarty offers a page level caching.

You can cache the entire page with Smarty’s caching capability. It is very easy to use. Just specify the $smarty->caching attribute and the whole page will be cached. The only downside I see is its inflexibility to cache the data in a more granular level. With a complicated database driven backend, we need to deal with different type of information we pulled from the database and decide whether to cache or how long to cache.

The Cache_Lite from PEAR is a great PHP lib to do this. It can take a String and cache it to a file, or talk a more complicated object and serialize it then cache it. Or you can use the serialize() /unserialize() method directly, like the way its done in the following code.

A “wrapper” class can be created to suite the need for caching different type of data:

require_once PEAR_DIR . “Lite/Cache/Lite.php”;
class CacheUtil {
private $cLite;
private $group;
function __construct($type = 0) {
// Set a few options
$options = array(
‘cacheDir’ => CACHE_DIR,
‘lifeTime’ => 3600
);
switch ($type) {
case TYPE_0:
$options['cacheDir'] = CACHE_DIR . “type0/”;
$options['lifeTime'] = 3600*24; // cache 1 day
$this->group = “type0″;
break;
case TYPE_1:
$options['cacheDir'] = CACHE_DIR . “type1/”;
$options['lifeTime'] = 60;
$this->group = “type1″;
break;
}
// Create a Cache_Lite object
$this->cLite = new Cache_Lite($options);
}
/*
* Takes an object needs to be cached, serialize it and store in the CacheLite
*/
public function set($cacheContent, $id) {
if (USE_CACHE == 0) {
return false;
}
$this->cLite->save(serialize($cacheContent), $id, $this->group);
}
public function get(&$cacheContent, $id) {
if (USE_CACHE == 0) {
return false;
}
if ($data = $this->cLite->get($id, $this->group)) {
$cacheContent = unserialize($data);
return true;
} else {
return false;
}
}
public function remove($id) {
if ($this->cLite->get($id, $this->group) !== false) {
$this->cLite->remove($id, $this->group);
}
}
public function clean() {
$this->cLite->clean($this->group);
}
public function nuke() {
$this->cLite->clean();
}
}
 Â

While using caching can definitely help speeding up the data retrieval if there is database involved, it also adds the complication to the code, for example: whenever there is any type of insert/delete/update, the cache will also need to be flushed if affected; caching is not free, it takes up the file system space too, therefore, a backend console for monitoring the caching usage is also needed to be considered.

Just another post of Google buying YouTube

Filed under: my 2 cents by 1.618 — October 16, 2006 10:31 pm

I know I know, people have been talking, blogging, and pod/tube/digg casting about this subject so much and you might have got tired of this. Just bear with me here. Google offered to buy YouTube with 1.6 billion dollars, in their stock. How much is Google worth today? $421. I guess the big question is: how much does it really worth? If you think Google is really only worth $100 a share, YouTube will be price around 400mil, in your price estimate. Still a hefty price though. Google's market worth is 128B, and if you have $128 in your wallet, will you pay $1.60 for a nice lunch? Absoluely. This is a great deal for Google. So everyone wins, I guess this is the beauty part of it. It almost feels like a website's value is again largely based on a perception these days. I don't want to predict the bubble, but can I quote Mr. Greenspan's word, "irrational exuberance"? :)

code customization of wordpress

Filed under: PHP development by 1.618 — October 15, 2006 4:24 pm

WordPress, with a nice backend system and highly customizable frontend, can be very powerful if you know how to tweak it. This post introduces some of the important php files that you may want to look into. index.php The index.php under the theme directory (for example, ./wp-content/themes/default), is the opening gate to access a wordpress site. It calls get_header(), get_footer(), have_posts() and the_content() functions that basically produce the web page. get_header() can be found in ./wp-includes/template-function-general.php. It calls up: header.php This is a simple page where you can include the category menus, etc. With the power of CSS, the menu can be moved from left to right, or top of the page. footer.php This is where the footer and the sidebar go. Similarly, it is called by the get_footer() function in template-function-general.php. As you can see, the small files under the theme directory call the general functions defined under wp-includes. for example, wp_list_cats() is in template-function-category.php have_posts() is in functions.php the_content() is in template-functions-post.php … Now, these template*.php files are not all we want to look at. The real meat is in the classes.php file. It has all the methods to make the database call to get the categories and posts. Method like get_posts() in the classes.php will be called by the wrapper functions (have_posts() in functions.php) and retrieve all the posts under a category. As you can see once you understand the structure, you can make different type of changes to create a website that suits your need, and not just a blog. With the the back end content management system, it's a nice and powerful package.

the web 2.0 look

Filed under: css/design by 1.618 — October 11, 2006 12:00 am

I would summary the web 2.0 look in these few words: bigger font and a lot of white spaces…:)

More and more web designers have realized that people come to web for quickfix of information, whether it is news, tools, or just fun stuff. People scan through the text and move around quickly. A simple design with less options on the page can actually help the users to read and surf.

benchmarking the server

Filed under: server setup by 1.618 — October 8, 2006 5:55 pm

Now I have the server ready and Apache web server is also up and running, it’s time to test drive this bad boy now.

I know this is a box with slow CPU (only an 8 year old AMD400) so the bottlenet is probably around the CPU process power.

Use Apache ab utility, I started:

./ab -n1000 -c10Â http://localhost/

This will send in 1000 requests with 10 simultaneouly.

In another window, I ran:

top d 1

This will give me the resource utilization every 1 sec.

The test is quite interesting. During the run, the CPU was running with 0% idle time and the load average was around 10-12 per second, which means there are always around 10 process waiting.

Although there were no request failing, the average time for each request was about 7 seconds.

Add a round corner to your menu without using images

Filed under: css/design by 1.618 — 11:26 am

Here is a great article about adding the roundish corner to your menu or div layer without having to involve the images for the corners.

Granted it has its limitations, for example, not showing too smooth on a dark background, but it is absolutely a smart idea and easy implementation (no need for those little corner images).

Next Page »

©phinesolutions.com