PHP programming shortcuts: save time and lines of useless code.

Posted: August 12, 2010 at 5:14 pm | (23) Comments

Before I even started writing this, I am sure that the comments will be filled about how consolidating code makes it hard to understand, more braces makes it easier to read, etc. This is for those who think it’s better to have less code, such as yours truly. I like seeing less code; I find it more efficient and much better.

Short-hand mathematical operators
Those are known by most programmers however missed by a lot, the following can be shortened by it’s alternative next to it.

1
2
3
4
$int1 = $int1 + $int2;  -- or alternatively:  $int += $int2;
$int1 = $int1 - $int2;  -- or alternatively:  $int -= $int2;
$int1 = $int1 * $int2;  -- or alternatively:  $int *= $int2;
$int1 = $int1 / $int2;  -- or alternatively:  $int /= $int2;

Counters
Here is another very simple one, but good to know for those who don’t know about it.

1
2
$int = $int + 1; -- or alternatively: $int++;
$int = $int – 1; -- or alternatively: $int--;

Short-hand print statements
Ever find yourself have to write so much just to be able to echo a variable in HTML? No more!

1
<?php echo $string; ?> -- or alternatively,  <?=$string?>

Braces: you don’t always need them.
You don’t always need to use the braces in any if or while statement if it only containers one directive.

1
2
3
4
if ($x)
{
echo "is x";
}

Could just be

1
if ($x) echo "is x";

Ternary operator
My personal favorite, saves a lot of time and I still think it makes readable code

1
2
3
4
5
6
if ($type == 'human')
{
echo 'human';
} else {
echo 'robot';
}

Or why not..

1
echo ($type == 'human') ? 'human' : 'robot';

You can even set variables using that method

1
$type_of_person = ($type == 'human') ? 'human' : 'robot';

Verifying zero values not being false
Sometimes we deal with a function that can return a number and we want to make sure it returns a number, but if it returns 0, PHP will consider it as false.

1
if (getNumber()) { …. }

The number can return 0 and be as false, where as the following will not consider the integer 0 false

1
if (getNumber() !== false) { … }

Alternative control structure syntax
This is a great feature to do when you’re trying to do a lot of PHP work with HTML, it would be hard to list all of them but you can refer to it here: http://www.php.net/manual/en/control-structures.alternative-syntax.php.

Feel free to post any other ones in the comments section.. we all have that one trick we always use!

Green Web Hosting: Going the extra mile

Posted: June 13, 2010 at 12:01 pm | No Comments

There are plenty of hosts out there claiming to be green only by buying renewable energy credits and not by taking the correct measures of decreases their power usage. Sure, renewable energy credits sound like a smart idea of “fixing” what you have caused, however, the consequences of what has been created have already been done.

We think of green web hosting in a different matter. We believe that we can provide a great service and also truly and literally reduce our environmental impact, not just by getting credits. Inside our offices and our datacenter, we are constantly looking for ways of reducing power usage (the biggest issues when working with a lot of computers and servers!)

To start everything, electricity is provided to both our datacenters and offices from Hydro-Quebec. Hydro-Québec is a government-owned corporation that generates, transmits and distributes electricity in the entire province of Québec. With sixty hydroelectric stations, Hydro-Québec is the largest electricity generator in Canada and one of the world’s largest hydroelectric generating companies.
What this means is that all the power that we utilize is renewable hydroelectric energy that causes almost no pollution when being generated. However, we don’t just stop there, just because we get power from a renewable source doesn’t mean we can do whatever we’d like with it.

Inside our offices, we don’t use desktops anymore. On every desk, there is a Apple MacBook Pro installed with a 24” LED Cinema Screen. The amount of power that a laptop uses compared to a regular desktop is much less as well as it gives the ability for our representatives to grab their workstation anywhere they can go.

Instead of running Ethernet inside the entire office, we’ve opted for a 802.11N wireless network, they can reach speeds of up to 108Mbps and that’s more than needed for an office (no, we don’t use wireless networks on our servers ;]) therefore, less wiring, less mess and less environmental impact. Our telephone system is entirely VoIP and connected to each workstation, so there is no need for phones, we have softphones installed on every Macbook Pro.

However, most of our power savings come from our datacenters. Our datacenters are extremely well cooled therefore after experimenting with servers, we found that there is no increase in server temperature when setting the fan setting to “Acoustic”. The acoustic setting lowers fan speeds (and there are a lot of fans in a server!). Also, we have opted to use Intel’s SpeedStep technology that underclocks the CPU’s frequency when it’s idle, when there is load, it will clock it back to default speed to process with no performance difference. We have also made some experiments and we have seen a big decrease in power when using Intel’s LV (low voltage) series of CPUs, they have the same exact power however run at a lower voltage.

One of the biggest power saving methods we have is virutalization, we are a certified and authorized Citrix XenServer partner and using their virutalization services has permitted us to consolidate multiple physical servers to one or two virtualized physical servers for all of our internal services.

All this is done to lower energy costs to provide you a much affordable service and decrease our environmental impact. We hope you enjoyed reading this article and if you have any suggestions on how we can decrease power in our daily operations, feel free to do so! :)

How synonyms affect Google search results?

Posted: January 26, 2010 at 7:12 pm | No Comments

Google announced a big change in how to handle the search results via adding synonyms for words that can be used in search. This should affect the position of web pages in Google’s search results.

It is important that Google can deal with synonyms.
Google wants to show the best results for search. Because of that, it is vital that Google’s algorithm get to know the words which are used in the search. The best way to understand these words is to check the synonyms of them.

What are synonyms: They are words that have the same meaning, for example “pictures” and “photos”. People searching for “sunset pictures” are probably also interested in web pages that contain the words “sunset photos”. A problem is that words that can have different meanings. For example, the word “case” can mean “occurrence”, “instance” or “example”. It can also mean “box” or “container”. The word “guitar box” might be a synonym for “guitar case” but “O.J. Simpson box” is not a synonym for “O.J. Simpson case”. Google’s measurements show that synonyms affect 70 percent of user searches across the more than 100 languages Google supports.

The Changes Google made
Google’s official blog posted that they have improved the way that they detect synonyms. For example, the algorithm can now find 20 possible meanings of the search term “GM”.

GM can mean General Motors, George Mason in [gm university], gamemaster in [gm screen star wars], Gangadhar Meher in [gm college], general manager in [nba gm] and even gunners mate in [navy gm], etc.

Google also made a change to how the synonyms are displayed. The searched words and the synonyms are now displayed in bold in the search results. Web pages that contain only synonyms of the searched word can also be displayed in the search results.

The Way Google Ranks Tweets – Official Google Statement by Amit Singhal

Posted: January 19, 2010 at 8:26 pm | No Comments

Google Search Engine started to show  real-time results side by side to the regular search result pages. These real-time results are meant to show web searchers an access to new and instant news items as fast as it happen.

The main components of Google’s real-time results are twitter tweets. These are the real-time micro-blog messages that Twitter users use to post news and activites. Google’s Amit Singhal, who led the development of Google’s real-time search, recently showed how Google ranks these tweets in the new real-time resultson Google search pages.

There’s some kind of Page Rank only for these twitter tweets.

Google’s Page Rank algorithm for standard pages is to looks at the link structure of a webpage. The more links to a website and the more links to the linking websites show more relevant the linked website is.

But tweets from twitter are not about links but its about followers. People “follow” the comments or tweets of other Twitter users. The more followers a Twitter user has, again the more reputable the tweets are for that user. If Twitter users who have many followers follow another Twitter user then these users can have a bigger impact to the reputation of that user.

“It is more than a popularity contest”, said Google’s Amit Singhal. “One user following another in social media is analogous to one page linking to another on the Web. Both are a form of recommendation.  As high-quality pages link to another page on the Web, the quality of the linked-to page goes up. Likewise, in social media, as established users follow another user, the quality of the followed user goes up as well.”

There are other filters and algorithms that rules this as the follower reputation rank is only one factor of Google’s methods to rank these tweets, other factors like hash tags, spam and the signal in the noise are some others.

- Hash tags: Twitter users use “hash tags” in twitter comments. Hash tags are symbols (like keywords) that start with a # followed by a popular topic, as an example of hash tag #earthquake. If this hash tag is included in a tweet, this tweet will start to show up in the real-time results when other Twitter users click that hash tag’s topic word elsewhere on the site.

- Spam: Hash tags can be very useful to maximize the exposure of a tweet, but sometimes they are abused for spamming. The wrong hash tags can become a red flag that triggers Google’s search spam filters. Amit Singhal didn’t go into the details in this but he said that Google modeled the hash tagging behavior in ways to reduce the exposure of spam or low-quality tweets.

- The signal in the noise: There can be thousands of tweets that has a very welknown word like “Obama”. To find the best relevant tweets, Google searches for “signals in the noise”. Such signal can be a huge number of tweets that mention other words relative to “Obama”, for example “Cambridge police”. These kind of tweets with these kind of signals will be chosen for the real-time results.

FFMPEG Automatic Installer

Posted: January 17, 2010 at 8:04 pm | (4) Comments

Our team at VEXXHOST has released a new utility that automatically installs all the applications required to encode videos on your server (FFMPEG, MPlayer, MEncoder, etc.)

It’s very simple and utility, all you have to do is just execute it and it’ll take care of everything afterwards.

Feel free to post on the forums or here if you have any questions, comments or any problems you see!

Also, of course, you can just sign up for hosting with us and we can help you setup everything here :)

Check it out: ffmpeg installer

Newer Entries »
« Older Entries

What our clients are saying — Read More →

I am a beginner in computers and internet, I bought my first domain name and my web hosting from vexxhost, I was having difficulties installing my blog, your technical support was very patient with me and help me install my blog. I know this is not their responsibility but they do it to help me, thank you support.


Kalie J.
Awards — View More →

Technology Partners