Thursday, January 31, 2008

PHP: Calculate PHP Page Load Time

//put this at the start of your php script.
$s_mt = explode(" ",microtime());

//put this at the end of your php script
$e_mt = explode(" ",microtime());
$s = (($e_mt[1] + $e_mt[0]) - ($s_mt[1] + $s_mt[0]));
echo "Page created in ".$s." seconds";

Monday, January 21, 2008

Javascript: Error, Internet Explorer cannot open the internet site

I have built a website that used a lot of javascript code to generate a floating overlay div, appends it to the body, and got this crazy Internet Explorer error in IE 6 AND IE 7.

Internet Explorer cannot open the internet site http://blah.blah.com/

Operation Aborted.


At which point I got redirected to a "The page cannot be displayed" IE error.

I trimmed everything out of the webpage which had nothing to do with the error and I was left with a tiny page which still produced the error:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<
html>
<
head>
<
meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<
title>pagetitle</title>
<
script language="JavaScript" type="text/JavaScript">
<!--
function creatediv()
{
try
{
document.body.appendChild( document.createElement("<div>") );//IE
}
catch (e)
{
document.body.appendChild( document.createElement("div") );
}
}
//-->
<
/script>
<
/head>
<
body>

<
div>
<
script language="JavaScript" type="text/JavaScript">
<!--
creatediv();
//-->
<
/script>
<
/div>

<
/body>
<
/html>


If you copy and paste the above, and then save it as html, and open the page in IE you will see the error. Then I googled around and played with my page, and realized that if I moved the creatediv() function outside the >div< (or any other html container), that I would no longer get this error. Basically, the problem is that IE 6 and 7 do not create the document.body part of the DOM until after the page has finished loading. In my javascript code I call document.body.appendChild and IE has a hissy fit. Something about calling the javascript from within a div or table makes also contributes to this error.

Workarounds and Solutions:
- moving my javascript function out of the div (see below)
- using <body onload='creatediv()' > instead of calling it within the page
- if using an event handler class like in http://www.dustindiaz.com/rock-solid-addevent/
use: addEvent(window,'load',creatediv);

Code that doesn't produce the error:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<
html>
<
head>
<
meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<
title>pagetitle</title>
<
script language="JavaScript" type="text/JavaScript">
<!--
function creatediv()
{
try
{
document.body.appendChild( document.createElement("<div>") );//IE
}
catch (e)
{
document.body.appendChild( document.createElement("div") );
}
}
//-->
<
/script>
<
/head>
<
body>

<
div>
<
/div>

<
script language="JavaScript" type="text/JavaScript">
<!--
creatediv();
//-->
<
/script>


<
/body>
<
/html>


source(s): http://tinyurl.com/hvfsw

Sunday, January 20, 2008

FLASH: Mp3 player swf plays chipmunk sounds

Most mp3s are encoded at 128 and 192 kbps, but I was working on a project that used speech recordings, and speech is usually encoded at a lower bitrate than 128. I found every time I played the recording in a flash based mp3 player it played it too fast, making it sound like alvin and the chipmunks.

I went through and made a whole bunch of mp3s at different bitrates using the lame 3.96 encoder to see which were supported and which bitrates were not.
fixed bitrates:
:( 16 kbps
:( 24 kbps
:( 32 kbps
:( 40 kbps
:) 48 kbps
:( 56 kbps
:( 64 kbps
:( 80 kbps
:) 96 kbps
:) 112 kbps
:) 128 kbps
:) 160 kbps
:) 192 kbps
:) 224 kbps
:) 320 kbps

variable bitrates (with lame; 0 is high quality, 9 is low):
:) V0-6
:( V7-9


So the basic synopsis is mp3s encoded as 48kbps work and anything greater or equal to 96kbps also works. Everything else is not supported (is support, but sounds like chipmunks).
[EDITED]
see
http://www.summitsolutions.co.uk/blog/how-to-correct-the-chipmunk-effect-in-the-podpress-flash-player
for another possible explanation of the chipmunk sounds.