PHP 5.3 Closures and their uses

0

As of PHP 5.3 you can now use something known as a closure in your php code. In PHP a closure is simply an anonymous function.
Here is an example of a closure

$upperCaseName = function($name){
return ucfirst($name);
};

which means that later on you can use this variable in the following way:

$name = "rachel";
$newName = $upperCaseName($name);
echo $newName;

This will output “Rachel”

None of the above is particularly useful. However there are some benefits to this as shown below.

If we have an array of Objects, from time to time we may want to perform a method on each of these objects and perhaps gather the result into a new array a closure can make this
into essentially a one liner. In the code below, I will first define a small class, then make some instances of the class and add them to an array. Then I will use a closure to perform a method on each object returning the result to a new array.


//first the basic class we want to make objects from and perform methods on
class person{
private $name;
public function __construct($name){
$this->name = $name;
}

public function cappedName(){
return ucfirst($this->name);
}
}

//an array of people
$person1 = new Person("peter");
$person2 = new Person("james");
$people = array($person1, $person2)

$resultArray = array();
//now the closure
array_map(function($row)use(&$resultArray){$resultArray[] = $row->cappedName();},$people);

print_r($resultArray);

//the output will be array([0]=>"Peter",[1]=>"James")

So to explain the above code: array_map is a normal php function which takes a callback function and an array. It then applies the call back to each element of the array. Normally we would have to define an external function and use that as the call back parameter, but with a closure there is no need as the function can be defined anonymously as the argument.
So in our closure we have an argument $row and then the “use” keyword. The “use” keyword allows our closure access to the external array $resultArray, we also use the & operator to pass it by reference. The body of our function is then simply assigning the return value of the call to $row->cappedName() into the $resultArray which can then be used for whatever purpose you may see fit.

A final interesting point about Closures is that they can be used as a Type. In other words when defining a function or method you can specify that the argument passed needs to be a Closure.
In the code below we ask for a Closure to use to format a name.

function formatName($name, Closure $closure = null){
if(! $closure){
$closure = function($val){ return ucfirst($val);}
}

return $closure($name);

}

So this code would allow the following:


$formatter = function($val){ return strtolower($val);}

$newName = formatName("JOHN",$formatter);

//this would return "john"

I hope that you have found this helpful. Happy coding in the future.

Regards Craig

Developer Hostingireland

Why isn’t my site on Google?

0

We often get asked “Why isn’t my website showing up on Google searches?”

For a large majority of internet users, Google is the internet.
Therefore; if your website is not in Google, then your website effectively doesn’t exist!
While not necessarily accurate, this is a viewpoint many people have.

In this post we will cover two important aspects of the relationship between your website and Google.

1. How do I get my site on Google?

You may or may not of heard about search engine “spiders”, these spiders crawl the internet as a spider crawls around it’s web.
These spiders are no more than intricate computer programs that visit every website they find.
Once your site has been visited by one of these spiders your pages will begin to be indexed in Google’s search results.

The question is, how do they know your website exists to visit it?

There are a few ways to ensure Google’s spiders know your website exists.

1. Probably the best way for Google to find your site is through a link on someone’s website. However this can be difficult to accomplish if you are new to this whole area.

2. Submit your site to Google; Google have provided a form that can be completed and submitted online. It can be found here : Submit your site to Google This can take a while however so it requires some patience.

3. Add Google’s Analytic code to your website; signing up to Google’s Analytic software alerts Google to your website’s existence.

All three of the above methods will end up with your site being indexed by Google. Once indexed your site will appear for searches for your domain name : e.g “hostingireland.ie”

2. How do I get more visitors from Google?

Getting top spot for competitive search phrases can bring your website the visitors you need. It’s all well and good coming top spot for people searching for your domain name, but how often do people search for that?

It is far more important to come high in the search results for terms around your business. For instance if you are running a car hire website, people looking for car hire in Dublin will generally type in to Google search phrases like :

Car hire Dublin
Cheap car hire in Dublin
Dublin car hire

This is where website optimisation comes in, optimising a website for performance in Google requires an understanding of the search phrases people are searching for around the services or products your website is selling.

Hosting Ireland offer services to assist you in getting your website to perform to it’s maximum in Google and other search engines. For more information please see our web marketing information or give us a call on 1890 987000 to discuss what we can do for your website.

Great Domain Discounts With Hosting

0

As you might have noticed, we have had various promotions running over the last few months. Unfortunately those promotions are over… For now. However we still have some great deals on Hosting and Domains.
From now on if you buy annual hosting and register a domain for a year at the same time, you will receive a discount on the cost of your domain registration. This isn’t a once off discount either, your renewal price will include the discount for as long as you keep the hosting account with us.

Discount Details

  • Pro Lite & Win Eco 25% Domain Discount
  • Pro Business, Win Pro & Win MYSQL 50% Domain Discount
  • Pro Ultima, Win MSSQL FREE Domain

The Discounts apply to annual domain registrations and hosting subscriptions.

If you buy a Pro Lite Hosting account or a Win Eco account, and choose a domain at the same time, you will receive a 25% discount on the annual cost of your domain.

If you buy a Pro Business Hosting account, a Win Pro or a Win MYSQL hosting account for the period of a year and choose a domain at the same time, you will receive a 50% discount on the annual cost of your domain name.

Free Domain

If you buy a Pro Ultima Hosting account or a Win MSSQL Hosting account for the period of a year & choose a domain at the same time, you will get that domain name for FREE for as long as you have that hosting account with us.

Protecting your website & pc from malicious software

0

As the internet becomes increasingly important in our day to day lives, the validity of it as a target for criminals grows exponentially. Viruses, Malware, Phising attacks and so on, all of these things can be confusing for the person who merely wants to access the web, browse a few sites and collect their email. Several sites put the number of new pieces of malicious software being launched on to the web at any where between 20,000 and 60,000 per day.

“More than 5 million U.S. consumers lost money to Phishing attacks in the 12 months ending in September 2008, a 39.8% increase from a year earlier (Gartner)”. That having been said, it does not mean that you cannot protect yourself from almost all of these forms of attack. Common sense is no small factor in removing the vast majority of threats. We all know the advice not to click on links and open unknown programs and emails from people we don’t know or that appear suspicious. Also a basic understanding of how the internet works and how your computer works, can go a long way toward protecting you from most threats. But even with this knowledge, your pc can still become infected. How? well malicious software makers don’t only target you and your pc they also look to find access to websites and install code on their pages. Then when visited, these pages will generally redirect you to a new site and before you realize it and often without knowing, your pc has downloaded and installed a malicious piece of software.

Our top 5 tips for protecting your pc & website

  1. Use an antivirus such as Eset Nod32
  2. Don’t store password in plain text use a password safe such as KeePass
  3. When sharing personal information on a site, make sure it is protected via https
  4. Air on the side of caution when downloading software from the web.
  5. Avoid opening emails and clicking links sent to you by people who you don’t know or trust

To be as safe as possible, you really need to consider using a well known antivirus software. Hostingireland recommends and also uses Nod32 antivirus. If you would like to try it out before purchasing then you can avail of a free trial .

Another important factor in protecting your websites and online accounts, is to use a password safe. This is a tool which encrypts the passwords that you enter into it, making it impossible for malware, should it become installed on your pc, to seek out these passwords and use them to gain access to your account. At hostingireland we use the free KeePass password safe

Benefits and Drawbacks of Dedicated Servers

0

As web services become more integral in people’s lives and the day to the day running of businesses, it is increasingly important that those services don’t fail. With the web being accessed not only from the home pc now, but also from mobile phones, music players, digital readers plus many more devices. The demand on the web services being accessed is also increasing, causing these services to require more and more resources in order to effectively deliver the service they offer.

When is a dedicated server needed?
The are many reasons why you may decide that you need a dedicated server. Security is a big reason. If you are planning on taking credit card payments and storing customers’ credit card details, so that they can reuse the same card for a later purchase for example, then you are required to have a dedicated server. As you can imagine, if you were doing this on a shared server, then there may be individuals also on that server which may try to access that information.
Another reason is that your web site or service may need to have more resources than a regular shared hosting account can offer. VPS hosting would be another option to look at in this case.
Perhaps you want a particular application stack set up on the server and configured exactly as you want it. This may not be possible on a shared hosting account and so once again you would need to look into either a VPS hosting account or a dedicated server.

So if you have a busy website or web service that is experiencing difficulties, what is the best solution for you? This is where dedicated servers come in. Dedicated Servers are seen as the best type of web hosting for people who are running large, popular resource intensive websites and web services, as well as businesses who need to be guaranteed a stable service that is more reliable than other types of web hosting, such as shared hosting and VPS Hosting; this is because a dedicated server is yours and only yours, meaning that you are not sharing it with anyone else and so are not sharing the resources on the server.

However there are drawbacks to dedicated servers. One of the main drawbacks of Dedicated Servers is there cost. The main reason for their high cost, is that a dedicated server is actually a physical machine. Other types of hosting accounts are one of multiples of that type of hosting on a single server or grid. However there is an increasing demand for dedicated servers as the web becomes more and more accepted as a place to do business and so, as a general rule the cost of dedicated servers is falling as they become cheaper to produce and the competition for providing them increases.

Another disadvantage of an unmanaged dedicated server, is that in order to look after and run it successfully, you would need someone with a reasonable amount of knowledge in either linux or windows system administration to manage your dedicated server. However you can opt for a managed server, which would mean one of the server engineers would be alerted if there were any problems and would then work to resolve them. Also on a managed server, any services that you wanted installed on your server would be done by one of the server engineers.

So what are the advantages? As stated previously, one of the main advantages with a dedicated server is that your service is the only one making use of the servers’ resources meaning that your applications would have priority and so be served faster than those based on shared hosting. Also because it is your server and yours alone, you can configure your application stack to run exactly the way that you want it to. If you want to run Java on your server, you can, if you want to run python on your server you can and so on.

There is also the added security that comes naturally when you are the only person running services on the server and accessing the server via ftp etc.. As the owner of the service, you would be able to spot possible flaws in your security. You would also have the added benefit of knowing that no one else is running code or services on the server that may potentially harm or reduce the security of your own service.

There is a lot to take into consideration before deciding to purchase a dedicated server. You need to know the level of resources that your are going to need. As a general rule, it is the processor and RAM that are the most intensely used resources. It is almost always possible to upgrade the RAM, but upgrading a processor may mean changing the physical server that you are on.

If you are thinking of investing in a dedicated server, then why not give us a call on 1890 7000 or drop us an email and one of our server engineers would be happy to talk through your requirements with you and discuss the options that available to suit your needs.

New Horde Groupware for Webmail

0

The latest version of cPanel offers Horde Groupware Webmail Edition. Horde Groupware Webmail Edition is a free, enterprise ready, browser based communication suite. Users can read, send and organize email messages with three different webmail interfaces and manage and share calendars, contacts, tasks and notes with the standards compliant components from the Horde Project. cPanel’s switch to Horde Groupware Webmail will provide you with the most up-to-date Horde modules.

This means you can have many of the features offered by products such as microsoft exchange, but at no extra charge as all of these features along with many others come free to you with our linux hosting accounts.

If you want to try out this new features, you can access webmail for your linux account by using the following url replacing example with your own domain name http://www.example.com/webmail. You will then
be asked for your username and password. The username will be you own email address and the password will be the password that you set through your control panel for that email address.

Tomcat 6 Java Hosting

0

We have recently upgraded our Tomcat Java hosting packages to have Tomcat 6 available to them. We have also increased the amount of diskspace given to the Java hosting accounts in General. The j2000 range of java hosting accounts now have 2GB of diskspace and the J4000 hosting accounts have 4GB of space available.

Tomcat 6 implements the following Java specifications: servlet 2.5 and JSP 2.1 specifications and uses J2SE 1.5 & JEE 5.

If you’re interested in ordering a java tomcat 6 hosting account please follow the link.

Big Domain Name Sale ie Domains and Others Half Price

0

If you are looking for a new domain name or to set up a new website, now is a great time to get started. With hostingireland you can now get a .ie domain name for half price. But not only a .ie you can also get a .com , .net, .info, .biz, .org or .name domain for half price over the next thirty days. To get a half price domain all you need to do is order your chosen domain.
So if you’ve got an idea for a site or have been toying with the idea of bringing your business on-line. Then get started right now and check if your domain is available add some hosting and off you go.

You can check a domain’s availability by following the link.

Joomla and Drupal CMS Software

0

If you are looking to set up a website and have little or no knowledge of code then using either Joomla or Drupal could be a good choice for you. Both of these open source software projects provide a full framework for creating a fully featured web site.

We provide an easy set up option for these software bundles within your hosting accounts control panel. Under Software and Services you will see an icon for scriptilous. When clicked this will launch the installer. From here you can then choose the software package that you wish to install within your hosting account. If you choose to install Joomla or Drupal, it will install the required databases and also the files that Joomla or Drupal require in order to run.

If you wish, you can choose to install these software bundles in a separate folder. Once installed you can simply browse to the folder where the software is installed. Once there you can login to the admin area with a user name and password that you would have been prompted to create when starting the installation. Then you are done and ready to begin creating your website.
Get a hosting account that supports Joomla and Drupal
Pro Ultima Hosting | Pro Business Hosting

Though it may be a little daunting at first, with some persistence and the help of some good, free tutorials on the web Drupal Tutorials and also Joomla Tutorials , you will soon have a dynamic, managable website up and running.