Godaddy 4GH Web Hosting Sucks

Recently, I found Godaddy.com was advertising a new hosting package called “4GH Web hosting” and it was claimed to be the “4th generation hosting”, which is cloud-based, “revolutionary”, even better than Rackspace, GoGrid etc. I was intrigued and signed up. The result? It’s been quite disappointing.

If you’ve been using other hosting services and familiar with cPanel, you’d find the control panel of Godaddy’s 4GH hosting not that user-friendly. It could take 5 minutes to add a new domain and even setting up a SQL database will involve something like 5 minutes’ waiting.

One of my projects needs an additional Perl module that’s not pre-installed. With other hosting companies, I can get it installed using cPanel or write a ticket and they will usually quickly get it installed. With Godaddy’s 4GH hosting service, there’s no way to install additional Perl modules in the control panel. When I ask them to help me, I got a plain No as the answer.

I’ve been using some PHP scripts that runs as cron jobs thus needs to be run as command line and those scripts failed mysteriously once I’ve moved my site to GoDaddy’s 4GH hosting. To my surprise, I found it you run those script via a web browser, they run without problem, but if I launch them in SSH, they all failed. I’ve also heard from other people that PHP scripts often have problem running on GoDaddy’s 4GH hosting.

I contacted their customer service, which is not that good either. While other hosting companies might take a couple of hours to reply a support ticket, it usually takes up to a whole day to get a reply for Godaddy 4GH’s supporting tickets, and the replies are mostly canned messages copied from their help section. When I contacted to the customer service reps from other hosting companies, I usually knew I was talking to a tech person, but at Godaddy, I got a feeling that those people who replied my technical tickets are not tech person at all.

Based on my experience with Godaddy’s 4GH hosting, I guess I must say: it really sucks!

 

 

Read More

PHP Cheat Sheet: Regular Expression

1. preg_match():

if (preg_match("/php/i", "PHP is the web scripting language of choice.")) {
    echo "A match was found.";
}

Note: $matches[0]will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.

$str = http://www.php.net/index.html;
if (preg_match('@^(?:http://)?([^/]+)@i', $str, $matches) {
    $host = $matches[1];
}

2. preg_match_all():

$str = "<b>example: </b><div align=left>this is a test</div>";
preg_match_all("|<[^>]+>(.*)</[^>]+>|U", $str, $out);
echo $out[0][0];  // "<b>example: </b>"
echo $out[0][1];  // "<div align=left>this is a test</div>"
echo $out[1][0];  // "example: "
echo $out[1][1];  // "this is a test"

 

$userinfo = "Name: <b>Joe Black</b> <br> Title: <b>PHP Guru</b>";
preg_match_all("/<b>(.*)<\/b>/U", $userinfo, $pat_array);
echo $pat_array[0][0];  // "Joe Black"
echo $pat_array[0][1];  // "PHP Guru"

3. preg_replace():

The preg_replace() function replaces all occurrences of pattern with replacement, and returns the
modified result.

$text = "This is a link to http://www.google.com/.";
echo preg_replace("/http:\/\/(.*)\//", "<a href=\"\${0}\">\${0}</a>", $text);
// "This is a link to
// <a href="http://www.wjgilmore.com/">http://www.wjgilmore.com/</a>."

If you pass arrays as the pattern and replacement parameters, the function will cycle through each
element of each array, making replacements as they are found.

$draft = "In 2010 the company faced plummeting revenues and scandal.";
$keywords = array("/faced/", "/plummeting/", "/scandal/");
$replacements = array("celebrated", "skyrocketing", "expansion");
echo preg_replace($keywords, $replacements, $draft);
// "In 2010 the company celebrated skyrocketing revenues and expansion."

4. Regular Expression Modifiers

  • i:     case-insensitive
  • m:     Treat a string as several (m for multiple) lines. By default, the ^ and $ characters match at the very start and very end of the string in question. Using the m modifier will allow for ^ and $ to match at the beginning of any line in a string.
  • s:    Let a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded.
  • U:    Turns off greety matching.

Read More

PHP Cheat Sheet: Working with Directories

1. Retrieving a Path’s Filename:

$path = '/home/www/data/users.txt';
$file_nm = basename($path);  // "users.txt"
$file_nm_1 = basename($path, ".txt");  // "users", no extension.

2. Retrieving a Path’s Directory:

$path = '/home/www/data/users.txt';
$dir_nm = dirname($path)  // "/home/www/data"

3. Learning More about a Path:

$pathinfo = pathinfo('/home/www/htdocs/book/chapter10/index.html');
echo $pathinfo['dirname'];   // "/home/www/htdocs/book/chapter10"
echo $pathinfo['basename'];   // "index.html"
echo $pathinfo['extension'];   // "html"
echo $pathinfo['filename'];   // "index"

4. Identifying the Absolute Path

$imgPath = '../../images/cover.gif';
$absolutePath = realpath($imgPath);   // "/www/htdocs/book/images/cover.gif"

5. opendir() and readdir()

if ($dh = @opendir($directory)) {
    while (($filename = readdir ($dh))) {
        if ($filename != "." && $filename != "..") {
            if (is_file($directory."/".$filename)) {
                echo "File: $filename";
            }
            if (is_dir($directory."/".$filename)) {
                echo "Dir: $filename";
            }
        }
    }
    closedir($dh);
}

 

Read More

PHP Cheat Sheet: File Handling

1. Checking Whether a File Exists:

if (file_exists("testfile.txt")) echo "File exists";

2. Reading from Files:

Method 1: Using fgets() to read one line a time:

$fh = fopen("testfile.txt", 'r') or die("Cannot open file.");
while (!feof($fh)) {
    $line = fgets($fh);
    $out .= $line;
}

fclose($fh);

Method 2: Using file_get_contents() to read the entire content:

$userfile= file_get_contents('users.txt');

3. Writing Files:

Method 1: Using fwrite():

// Regular writing, no locking.
$fh = fopen("testfile.txt", 'w') or die("Failed to create file");
fwrite($fh, $text) or die("Could not write to file");
fclose($fh);

// Writing with locking
$fh = fopen("testfile.txt", 'w') or die("Failed to create file");
flock($fh, LOCK_EX) or die("Cannot lock file");
fwrite($fh, $text) or die("Cannot not write to file");
flock($fh, LOCK_UN) or die ("Cannot unlock file");
fclose($fh);

// File append
$fh = fopen("testfile.txt", 'a') or die("Failed to create file");
fwrite($fh, $text) or die("Could not write to file");
fclose($fh); 

Method 2: Using file_put_contents():

// No appending
file_put_contents('output.txt', $data) or die("Cannot write file");

// File append
file_put_contents('output.txt', $data, FILE_APPEND) or die("Cannot write file");

4. Determining a File’s Last Modified Time:

echo "File last updated: ".date("m-d-y g:i:sa", filemtime($file));

5. Determining a File’s Size:

$bytes = filesize($file);
$kilobytes = round($bytes/1024, 2);


 

Read More

How to Register a Facebook Application

Before registering a new Facebook application, you need to make sure you have verified your Facebook account. There’re two ways to verify your developer account:

1. You can confirm your phone number at the fololowing URL: http://www.facebook.com/confirmphone.php

2. You can verify your Facebook account by adding your payment (credit card information) at here: https://secure.facebook.com/cards.php

Once your Facebook account has been verified, you can go to this page to register a new Facebook application: https://developers.facebook.com/apps. Just click on the “+ Create New App” button and enter the detailed information about your new application.

Once registered, you will be given a application ID and a application Secret. These two pieces of information is very important. You will need them when developing your application.

Read More