PHP >> SerialCom project using WAMP (locally) (now w/Flash front end)

Hello friends, I'm new to arduino. I'm trying to make a distance reader in PHP using HC-SR04 ultrasonic sound sensor with a arduino (without ethernet shield). Basically I need to show distance data on the PHP page. Although I tried the following method it didn't work :confused: . How should I capture and display this sensor data using PHP.

My Arduino Code:

/* HC-SR04 Sensor

  • TRIG connection of the sensor attached to digital pin 2
  • ECHO connection of the sensor attached to digital pin 4
    This example code is in the public domain.
    */

const int trigPin = 2;
const int echoPin = 4;

void setup() {
Serial.begin(9600);
}

void loop()
{
long duration, cm;

pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);

cm = microsecondsToCentimeters(duration);

Serial.print(cm);
Serial.print("cm");
Serial.println();

delay(1000);
}

long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}

My PHP Code:

<?php exec("mode COM32 BAUD=9600 PARITY=N data=8 stop=1 xon=off"); $fp = fopen("com32", "w"); if (!$fp) { echo "Not open"; } else { sleep(10); echo "Port Open"; $string = fgets($fp); echo $string; fclose($fp); } ?>

info:
Port : COM32
PHP version : 5.5.15
Platform : Windows 8.1