Posts Tagged ‘time’

What is Cookie?

Tuesday, July 29th, 2008

The most common meaning of “Cookie” on the Internet refers to a piece of information sent by a Web Server to a Web Browser that the Browser software is expected to save and to send back to the Server whenever the browser makes additional requests from the Server. Depending on the type of Cookie used, and the Browsers’ settings, the Browser may accept or not accept the Cookie, and may save the Cookie for either a short time or a long time. Cookies might contain information such as login or registration information, online “shopping cart” information, user preferences, etc. When a Server receives a request from a Browser that includes a Cookie, the Server is able to use the information stored in the Cookie. For example, the Server might customize what is sent back to the user, or keep a log of particular users’ requests. Cookies are usually set to expire after a predetermined amount of time and are usually saved in memory until the Browser software is closed down, at which time they may be saved to disk if their “expire time” has not been reached. Cookies do not read your hard drive and send your life story to the CIA, but they can be used to gather more information about a user than would be possible without them. From Matisse

Introduction to Web Hosting

Wednesday, July 16th, 2008

Just about anybody can create a presence on the Internet. Building a web site can be as simple as using a word processor, but once you have the site you need a way to publish it on the World Wide Web. This is where web-hosting companies come in.

A web host rents you disk space and provides all the services necessary for others to see your web site on the Internet.  Barring technical problems, a web host operates 24 hours a day, 7 days a week so that anybody in the world can access your web site at any time.

There are literally thousands of web hosts to choose from so choosing an appropriate host can be a difficult task. The prices range from free to hundreds of dollars a year. Hosting companies can offer a multitude of services that can be confusing to a newcomer. This series of articles will help you to sort out all the information available and give you the confidence to make the proper decision about choosing a web host.

Free or Paid?

There are plenty of hosting companies that provide free hosting, so why bother paying for it?  The old adage ‘You get what you pay for’ is just as valid in the electronic age as it was 100 years ago. In web hosting, when you pay nothing you sometimes end up with nothing.

Most free web hosts offer limited services. Even though they are not charging you to host your website, they still need to make money. They often do this by placing advertising on your site. You probably won’t have any control over what kind of ads show up – it’s a matter of take it or leave it.

In addition, free hosts may restrict the content you place on your site. You may not be allowed to sell things or have certain content such as videos or music. Finally, your web site could simply disappear overnight. New companies that offer free hosting pop up almost everyday, but they also vanish with astonishing regularity. When your hosting company vanishes, your web site goes with it.

If you are serious about having a web site you need to use a reliable web host. Prices range considerably – some companies offer rates as low as $2 a month while others charge $60 or more. Be careful, though. High rates don’t always translate as high service. Some of the lower priced hosts offer reliable, stable environments that allow your website to be accessed day in day out for years.

Generally speaking the more you pay the more you get. Higher rates should bring you more storage space, more bandwidth to handle Internet traffic, and more services such as databases, email accounts, mass mailers, and the ability to add custom scripts. Higher rates can also mean better technical service if you have problems with your website.

What is a Web Server?

Whichever hosting company you choose, it helps to understand some of the technical details about their service. Every host has dedicated computers called servers which connect to the Internet and ’serve’ pages when they are requested.  That is, whenever anyone wants to see a certain web page by clicking on a link the request is sent to the particular server where that web page is stored. The server responds by sending HTML data across the Internet. A web server must have fast connections to be able to serve pages quickly. For the greatest speed and reliability try to find a host that has multiple high-speed connections as well as reliable back up power supplies in case of power outages.

Search engine optimization-Add new content all the time

Tuesday, July 15th, 2008

Sites that have new content added on a regular basis are seen as more reliable than sites that rarely do. This also helps you to increase the amount of relevant content on your site, which also improves your rankings.

ini_alter vs ini_set in php

Tuesday, July 15th, 2008

Finally lets look at modifying the environment. I actually cheated here and just set the max execution time to 60 seconds a million times. I think the result is still valid though

ini_alter vs ini_set
ini_alter: 103.332370043 seconds
ini_set: 86.2883789539 seconds
Time saved: 17.0439910889 seconds; 19.7523598143%

As might be expected these functions are expensive when it comes to execution time. That 17 microsecond saving is massive as well making ini_set the superior choice.

MYSQL:Calculate TIMEDIFF with mysql version < 4.1

Monday, June 30th, 2008

// TIMEDIFF between two dates and the result is in seconds
SELECT ((TO_DAYS(DATE_FORMAT(’1997-10-04 22:23:00′, ‘%Y-%m-%d’)) * 86400) +
TIME_TO_SEC(DATE_FORMAT(’1997-10-04 22:24:00′, ‘%T’)))
- ((TO_DAYS(DATE_FORMAT(’1997-10-04 22:24:00′, ‘%Y-%m-%d’)) * 86400) +
TIME_TO_SEC(DATE_FORMAT(’1997-10-04 22:22:00′, ‘%T’)))

PHP:extend php script lifetime ( max_execution_time )

Monday, June 30th, 2008

ini_set( ‘max_execution_time’, 120 );

PHP:Update user last login time

Monday, June 30th, 2008

//updates last login time
$USER_ID = $_SESSION[ 'USER_ID' ];
$last_login = gmdate(”Y-m-d”);
$sql = “UPDATE somedb.users SET last_login = ‘$last_login’ WHERE id = ‘$USER_ID’”;
$result = @mysql_query($sql,$connection) or die(mysql_error());

Use time() rather than date(’U')

Saturday, June 28th, 2008

When you want to get the current Unix timestamp, it is faster to use time() rather than date(’U'). To test this, I used the time() function 100,000 times, followed by date(’U') 100,000 times. My results are as follows:

date(’U'): 19.162 seconds
time(): 0.057 seconds
Time saved: 19.105 seconds; 99.7%

split() or explode()

Saturday, June 28th, 2008

The split() function supports regular expressions, while explode() does not. It is often faster to use explode() when you do not need to use regular expressions.I done yet another test. I used split() to split a string without regular expression requirements, and then used explode() to split the same string. I repeated this 1,000,000 times. My results are:

split(): 5.453 seconds
explode(): 3.556 seconds
Time saved: 1.897 seconds; 34.79%

Displaying Page Loading Time (Steps and Sample Code)

Saturday, June 28th, 2008

Here is how to display your page’s loading time:

1. Use the function microtime() to get the time in micro-seconds
2. Use the explode() function to turn the micro-time into an array.
3. Combine the two parts to the array (the micro-seconds to the seconds).
4. Repeat steps 1,2 and 3 for the bottom of the page
5. Take the time taken at the end of the page from the time taken at the top of the page to determine the total loading time.
6. After rounding the microtime, return it to the browser.

At the top of your page, place:

$m_time = explode(” “,microtime());
$m_time = $m_time[0] + $m_time[1];
$starttime = $m_time;
?>

At the bottom of your page, place:

$round = 3;// The number of decimal places to round the micro time to.
$m_time = explode(” “,microtime());
$m_time = $m_time[0] + $m_time[1];
$endtime = $m_time;
$totaltime = ($endtime - $starttime);
echo “Page loading took:”. round($totaltime,$round) .” seconds”;
?>