Forum Moderators: coopster

Message Too Old, No Replies

PHP redirects and site performance in WMT

Is PHP slow by its nature?

         

smallcompany

6:59 am on Dec 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I touched this topic under Google Search News, but thought that direct related PHP question should be asked here.

I'm in affiliate business. I use PHP redirects for outgoing links for two main reasons:

- tracking
- easiness of link maintenance at one place

Average PHP script is anywhere between 10 to 100 lines

All what happens inside is something like this:

- Make a call to another script that has those lines:


$v1 = $_COOKIE['var1'];
if ($v1 == "something")
{
$v2 = "something-else";
} else {
$v2 = $_COOKIE['var2'];
}// end IF
$v3 = $_COOKIE['var3'];
$s = $_GET['s'];
$final = "$v1-$v2-$v3-$s";

- Then I have a list of 5-80 links like:

if ($s == "link1") {$link = "http://www.example.com";}

- And finally the header:

header("Location: $link$final");

This above is the all crunching that happens on the servers where I host my sites. The servers are either shared hosting or VPS.

In Webmaster Tools, Google shows my HTML files to be loading in about 1 second, while those PHP files are taking up to 8 seconds.
To add bit of irony, shared hosting processing seems to be faster than VPS with prominent hosts.

Anyway:

1. Do you think that PHP is slow by its nature?
2. From end user perspective, how do you compare the speed of PHP to other programming solutions?
3. Probably silly question, but is my code any time demanding?

All what I want is to shed away the possibility of PHP being a real cause of my sites being slow in Google's eyes.
As the "Site performance" is (I believe) in its experimental phase from ranking factor perspective, I would like to point out to this part so we get ready in early 2010.

Thanks

coopster

1:36 pm on Dec 31, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



<WARNING: high level summarization ahead>
Languages aren't slow, so to speak. Languages are used to develop source code which is compiled into machine-readable programs, which in turn run faster. Every step you can eliminate along the way makes a program even faster, including well-structured code, or "optimized" code as we say. If you developed all your programs in C and compiled them and then configured CGI to handle your requests they would theoretically run faster than say a perl or php script that is compiled at run time.

That said, with today's interpreters and processors you likely won't notice the difference ;)

If your PHP code is taking 8 seconds to process simple functions as this you need to address something as this just doesn't sound right. A mere 100 line script without any loops should be over in milliseconds. Are you certain it is your script and not an external call or something else?

One note regarding your "if" control structure there. Rather than:

if ($s == "link1") {$link = "http://www.example.com";}

... you may consider a switch or even an array. I would likely use an array.
$links = array( 
'link1' => 'http://www.example.com',
'link2' => 'http://www.example.net',
'link3' => 'http://www.example.org'
);
$link = isset($links[$s]) ? $links[$s] : false;
if ($link) {
header("Location: $link$final");
exit;
}

... something like that anyway.

smallcompany

11:03 pm on Dec 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks.

If your PHP code is taking 8 seconds

That's per Google's WMT, not in my real world. I'm just trying to determine how they develop numbers that are over 2 seconds. Among other things, I would like to see if I can change it by changing PHP code.

It may also be that Google is doing something wrong when they calculate this.

TheMadScientist

11:51 pm on Dec 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would like to see if I can change it by changing PHP code.

Create a PHP test page with a redirect on it.
Submit it to Google.
Check the time in WMT.
You'll have your answer...

Test.php = <?php header('Location: http://www.example.com/'); ?>

Just a note... Your redirects are 302's unless you precede them with:
header('HTTP/1.1 301 Moved Permanently');

Or, some other defined redirect status.
IDK if the preceding has an effect on how they calculate things, but it's worth looking at.