Zend Server Tutorial Example Code 1

Note:

Remember to delete the PHP tags that are inserted by default when creating a new PHP file before pasting in the code.

Copy this code into your editor to test Zend Server Event Profiling:

<?php

/**

 * Converts Fahrenheit to Celsius (and back again)

 *

 * This sample application takes a number of degrees entered by the user and

 * converts them from Fahrenheit to Celsius or vice versa

 *  

 */

?>

<html>

<head>

<title>Fahrenheit / Celsius PHP Convertor<MadCap:variable name="Primary.pageTitleVersion" /></title>

</head>

<body>

<h1>Fahrenheit / Celsius PHP Convertor</h1>

<form method="get">

Enter number of degrees: <input type="text" name="degrees" /><br />

<select name="conversion">

<option value="ctf">Celsius to Fahrenheit</option>

<option value="ftc">Fahrenheit to Celsius</option>

</select>

<input type="submit" value="Convert!" />

</form>

<?php

function myFunction(){

$degrees = (int) $_GET['degrees'];

 

switch($_GET['conversion']) {

 

// Convert Celsius to Fahrenheit

case 'ctf':

convertCTF($degrees);

break;

// Convert Fahrenheit to Celcius

case 'ftc':

convertFTC($degrees);

break;

}

 

 

 

//create a slow down in performance

for ($a=0 ; $a<10000 ; $a++){

for ($b=0 ; $b<1000 ; $b++){

$c++;

}

}

}

function convertCTF($degrees){

$result = sprintf("%0.2f", $degrees * 9 / 5 + 32);

$message = "$degrees&deg; Celsius is $result&deg; Fahrenheit";

printMessage($message);

}

function convertFTC($degrees){

$result = sprintf("%0.2f", ($degrees - 32) * 5 / 9);

$message = "$degrees&deg; Fahrenheit is $result&deg; Celsius";

printMessage($message);

}

function printMessage($message){

echo "<hr /><strong><em>$message</em></strong><hr />";

}

if (isset($_GET['degrees']) && isset($_GET['conversion'])) {

myFunction();

}

?>

</body>

</html>

Back to "Working with Zend Server"