Arduino and PHP

Please use the # button for code

It might be that PHP closes the serial port, causing the Arduino to reset. Can be tested with modified code below

String val;

void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  for(int i=0; i<5; i++)
  {
    digitalWrite(13, HIGH);
    delay(100);
    digitalWrite(13, LOW);
    delay(100);
  }
}

void loop()
{
  while (Serial.available())
  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') break;
    val += c;
     if (val.length() >10) break;
  }

  if (val.length() >0)
  {
    if (val == "on")
    {
      digitalWrite(13, HIGH);
      Serial.println("The value is on");
      val = "";
    }
    else
    {
      digitalWrite(13, LOW);
      Serial.println("The value is off");
    }
  }
}