How to: Load My Configuration Data

What is the best way to load your web application configuration? All web applications today have at least a single configuration file or multiple ones. What is the best way to load your configuration file? from database, from an XML file, from INI file or from SESSIONS??? To find out which method is the best I decided to run a few tests for each method and to see the time that a method required to be executed and how much memory it needed.

My conclusions where that as many times as I run the tests saving configuration data in sessions is the fastest way with a slightly difference in memory usage which increases a bit compares to loading from the INI file. Loading the configuration settings of your application in sessions or INI file saves resources and improves performance. I thing that a good practice is to have configuration in INI file and when ever the file updates to load the configuration for each visitor in its sessions instead of reading from INI. But at what cost?

Below you can see the results generated on the fly. http://digitzone.net/classes/PerformanceTests/

Write & Read UTF-8 from Mysql

The following php script shows how we can write and read Greek characters in a mysql database. Before starting check the encoding of your file. If you are using Zend studio go to Edit->Set Encoding and select Other: utf-8. Now in your php script after establishing a connection to the database type the following queries in order to set the names and characters equal to utf-8 for the specified connection, for me is just one connection so I do not use the resource as a parameter.

mysql_query(“SET NAMES ‘utf8′”);
mysql_query(“SET CHARACTER SET ‘utf8′”);

Next you can type you insert query:

$query = sprintf(‘INSERT INTO test (text) VALUES (“%s”)’, ‘write greek text here’);
mysql_query($query);

And finally you can start reading from your database:

$q = mysql_query(“select text from test order by text”");
$row = mysql_fetch_object($q);

while($row){
echo $row->text;
$row = mysql_fetch_object($q);
}

This small piece of information can save you a lot of time when trying to handle utf-8 characters. Good luck.

Clean-Up your code!

Clean code means readable code by anyone, no duplications, faster performance and the best thing of all is you can edit that code easier.

JAVASCRIPT : a very good website that can tide up your code especially if is a big mess and you cannot read or edit the code use: About.com – Javascript Formatter. Just copy and paste your javascript code inside the textarea and press clean.

CSS : cascading style sheets. No more having the same class more than once or classes that do the same thing. By using the
W3C CSS Validation Tool 1st it will validate your code and 2nd generate for you a clean version
of your css code nice and tide.

PrettyPrinter.de

If you would like a more sophisticate source code formatter I believe PrettyPrinter is the best I used so far. Visit Site. The reason is that this site enables the user to customize the code format according to its needs. The following parameters can be applied:

  • Add new lines after “{” and before “}”
  • Add new lines before “{“
  • Remove empty lines.
  • Add comment lines before function.
  • Add new lines after “;”
  • Add new lines after “}” (For .css) (Thanks David)
  • Remove new lines (useful only if you add them again with the other functions above)
  • Add new lines after “;” but not in for loops (Don’t check “Remove new lines” but do check “Remove empty lines”)(Thanks Chris) (Experimental, uses a heuristic that might fail )
  • Add new lines after “;” but not in for loops and skip quotes (Don’t check “Remove new lines” but do check “Remove empty lines”) (Thanks Chris) (Experimental, uses a heuristic that might fail )
  • Reduce whitespace
  • Put the code again in the input box above after submit.
  • Skip HTML, give me plain code! (Use Save-As function of your browser)

PN Generator (Pagination)

This class can be used to generate links to browse MySQL database query results split in multiple pages.

It takes as parameters an SQL query and a limit number of results to display per page.

The class executes the query to obtain the total number of results and generates HTML links to browse to the next, previous and other pages over which the query results will be displayed.

Inside the zip file there is a file called example1.php which you need to configure first by setting up your database connection strings, your query and how many results to display in each page.

  • You can download the class file here.

SEO – The basics

SEO which stands for Search Engine Optimization is a must for every site that is been made. If you would like your site to get a good ranking into different search engines like Google, Yahoo and other you must follow some basic rules. I believe that even a novice user can do SEO its website without the knowledge of how to program for a start. The following are some rules that I wrote down that I came across for my convenience and yours to help keep a site consistent and adhere to the latest standards of W3C.

01. Specify a DOCTYPE at the top of your page. An example of a DOCTYPE is:

DOCTYPE

02. The following must be present inside the head of your page:

HTML HEAD

03. The Url & Title of your website are very important and you must give it some thought first.

04. Sizes:

- Title size 80 chars,
- Keywords size 20 chars,
- Description size 250 chars related to site content
and for each page individually

05. The H1, H2 tags are very important as it shows the importance of your content.

06. Tide up your code to help crawler crawl your site easier and faster.

07. Join multiple CSS file into one for faster loading

08. Remove unnecessary CSS classes or id’s, js functions or files, php functions or files.

09. IMAGES

- check all images if exists
- check images size, create thumbnails for better performance
- check out transparent images how they look in different browsers (old browsers)
- create alt tags for each image !very important

10. Check your site into different browsers for compatibility issues.

11. Address on Page: Putting your business address at the footer (or header) on every page of your site is a great way to help the engines to identify your location.

12. WEBSITE VALIDATION: Go to the following site and check your site to see if it adheres to the latest standards.

- XHTML VALIDATION: http://validator.w3.org/
- LINKS VALIDATION: http://validator.w3.org/checklink
- CSS VALIDATION : http://jigsaw.w3.org/css-validator/

13.Optionally you can check for broken links by using an application like XENU

14. ADD your site to different search engines like Google, Yahoo. You can start from addme.com

15. You can use Google Analytic s is an online facility for obtaining traffic analysis of your website and how is your site doing.

16. Add you URL into different sites (back links) get more traffic.

17.SEOMOZ: in this site you can find different seo tools to help you get started.

PHP: debugTool

DebugTool v1.0 is a new project that will help php developers to use it on the fly to check if their website is working right. Using this tool it will save them time from trying to figure out why something is not working, are my variables set, clean session and request variables on the fly without closing your browser every time.

Snapshot of debugTool:

Snapshot of debugTool with comments:



  • A Demo for this project can be found here.
  • Download project debugTool v1.0 here.