Posts Tagged ‘expensive’

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.

Tips for optimizing your php code

Saturday, June 28th, 2008

# If a method can be static, declare it static. Speed improvement is by a factor of 4.

# echo is faster than print.

# Use echo’s multiple parameters instead of string concatenation.

# Set the maxvalue for your for-loops before and not in the loop.

# Unset your variables to free memory, especially large arrays.

# Avoid magic like __get, __set, __autoload

# require_once() is expensive

# Use full paths in includes and requires, less time spent on resolving the OS paths.

# If you need to find out the time when the script started executing, $_SERVER[’REQUEST_TIME’] is preferred to time()

# See if you can use strncasecmp, strpbrk and stripos instead of regex

# str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4

# If the function, such as string replacement function, accepts both arrays and single characters as arguments, and if your argument list is not too long, consider writing a few redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments.

# It’s better to use select statements than multi if, else if, statements.

# Error suppression with @ is very slow.

# Turn on apache’s mod_deflate

# Close your database connections when you’re done with them

# $row[’id’] is 7 times faster than $row[id]

# Error messages are expensive

# Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time.

# Incrementing a local variable in a method is the fastest. Nearly the same as calling a local variable in a function.

3 Things You MUST Know Before Buying Web Hosting

Thursday, June 26th, 2008

1: Too Few Databases

All blogging software, all forum software, and darn near every cool Web application you can think of requires a database in order to function. Unfortunately, most shared server packages only offer between 1 and 5 databases, thereby limiting your ability to expand with new sites or to experiment with new ideas.

In my opinion, this is completely unacceptable. If I want to see if I can tie 10 databases into one WordPress installation, then by god, I ought to be able to do that! Sadly, this would be an impossible task with just about every shared server package I’ve ever seen.

Because of this limitation, I have resorted to purchasing more expensive plans that offer more flexibility. Remember my first inadequate server that I told you about earlier? After that terrible experience, I opted for a more expensive server that cost me roughly $550 up front, and the primary reason why I went with the more expensive unit was because I could have unlimited databases.

2: Too Few Domains Allowed

Probably in an attempt to curb spammers, Web hosting companies usually limit the number of domains you can have on a shared server. Oftentimes, the limit is between 1 and 5 domains, but just like with the databases, this really affects your flexibility over time.

Want to start that new site you’ve been thinking of lately? Too bad, you’ll have to buy new hosting because you’ve already maxed out your domains.

Oh, and here’s another gem from the crazy world of Web hosting… I’ve seen shared server accounts before that would let you have 5 domains but only 1 database. If every site on the planet requires a database to run, how the hell can you run 5 domains with only one database?

Sanity? Anyone?

The bottom line—and the thing you really need to know here—is that good shared server plans will offer you at least 20 domains, and even better ones will let you add as many as you like (usually up to 999).

3: Crappy Developer Support

So, that new version of WordPress you want to run requires MySQL 4.0 or higher in order to work properly? What a shame, because your junky shared server only runs MySQL 3.23 and hasn’t been updated since 2005.

Of the three cardinal sins I’ve listed here, this one is probably the easiest to avoid. However, developer support is the ultimate litmus test for any Web host, and you can bet your bottom dollar that if the company you’re looking at doesn’t consider developers a priority (we’re a raucous, complaining bunch), then they damn sure won’t consider you a priority.

No matter what hosting package you’re looking at, make absolutely certain that you see support for the following developer tools:

* PHP
* MySQL
* Ruby on Rails
* Python
* CGI
* .htaccess
* cron jobs

Managed Versus Unmanaged Dedicated Web Hosting

Thursday, June 26th, 2008

If you have a large and complex website that receives a lot of traffic you may find that shared hosting is limiting your growth and the capacity to serve your customers. It may be time to move on to dedicated hosting. Shared hosting involves placing many websites on one server. All sites share the resources of that server such as disk space and bandwidth. Dedicated hosting means that instead of renting space on a server, you rent an entire server for your sole use.

Dedicated web hosting is much more expensive than shared hosting because the cost of operating the server is not divided between various accounts. The advantages of dedicated hosting include the freedom to use the resources of the server as you please. There are many different dedicated hosting packages to choose from. Their prices depend largely on the physical setup of the server computer. Just as with your home computer, faster processors and bigger hard drives cost more.

Another factor influencing the price is whether or not the server is managed. Keeping a server running in top condition can be a time consuming task. A managed hosting service offers the support and expertise to maintain your server and to perform routine maintenance such as software upgrades. This kind of service can be a viable alternative to hiring your own staff to look after your servers. Managed hosting, however, can be a lot more expensive than unmanaged hosting.  Whether the price is justified depends on the complexity of your website and whether or not you already have people on staff who can look after the day to day operations of a server.

Unmanaged hosting, despite its name, does not really leave you entirely to your own devices. Most hosting companies will offer a certain level of support for all their dedicated hosting packages. This support of course includes hardware maintenance for things like hard drive failure and extra technical support may be available if you need help with configuration or software installation. You will probably have to pay for this extra support but hiring a tech on an hourly basis from time to time may be cheaper than going with a full managed package.

If you are considering unmanaged hosting check to see how much control you can have over the server hardware. If your server becomes hopelessly locked you should be able to perform a re-boot or to expect someone to do it for you with a minimum of delay.

As with any hosting package the value of a dedicated hosting service depends on the reliability and integrity of the hosting company. If your website has grown to the point where you need dedicated hosting you need a hosting provider that you can rely on to keep your site online as much as possible.

Whether you choose managed or unmanaged hosting depends on the technical requirements of your site and the ability of you or your staff to manage a server so that it is running at peak efficiency. If you prefer to have the re-assurance of having highly trained professionals looking after the server, go with managed hosting. If you or your staff can handle most of the maintenance chores, you would be better off with an unmanaged server.