title: PHP overflows the arduino buffer
body: <p>I have a problem with arduino (uno) buffer overflow. I am trying to create a simple application in which I insert b (blue diode) or r (red diode) or space (space does not turn on any diode) through the PHP page into the form, send it and then the blue or red diode lights up. Arduino connected via USB (COM3)
  Specifically: I insert "br r b rbrb" into textarea the first 9 characters are displayed by diode light, but after the ninth character arduina buffer is probably filled and other characters are displayed (by diodes) after about 10 seconds. If anyone knew how to fix it I would like to thank you.</p>
  
  <p>BTW if i use serial monitor in arduino app this problem is not and the buffer will not fill so arduino will process the whole string ("br r b rbrb") without jamming on the ninth character</p>
  
  <p><strong>Arduino code:</strong></p>
  
  <pre><code>int red_2=4;
  int blue_1=5;
  
  void setup() {
    Serial.begin(9600);
  
    // set diodes for outputs
    pinMode(red_2, OUTPUT); // red
    pinMode(blue_1, OUTPUT); // blue
  
  
    //all diodes going LOW in start
    digitalWrite(red_2, LOW);
    digitalWrite(blue_1, LOW);
  
  }
  
  void loop() {
    char var_characters;
  
  
    if (Serial.available() &gt; 0) {
      var_characters = Serial.read();
  
      if (var_characters == ' ') {
        Serial.println("Reading charakter: 'space' ");
        delay(500);
        digitalWrite(red_2, LOW);
        digitalWrite(blue_1, LOW);
      }
  
      if (var_characters == 'b') {
        digitalWrite(blue_1, HIGH);
        Serial.print("Reading charakter: ");
        Serial.println(var_characters);
        delay(500);
        digitalWrite(blue_1, LOW);
      }
  
      if (var_characters == 'r') {
        digitalWrite(red_2, HIGH);
        Serial.print("Reading charakter: ");
        Serial.println(var_characters);
        delay(500);
        digitalWrite(red_2, LOW);
      }
    }
  } 
  </code></pre>
  
  <p><strong>PHP code:</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;PHP and Arduino&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;?php
          exec("mode COM3: BAUD=9600 PARITY=n DATA=8 STOP=1 to=off dtr=off rts=off");
          $port = fopen("COM3", "w+");
          sleep(2);
      ?&gt;
  
      &lt;center&gt;
          &lt;h1&gt;PHP and Arduino&lt;/h1&gt;
  
          &lt;form method="post"&gt;
              Message: &lt;textarea type="text" name="msg_form"&gt;&lt;/textarea&gt;
              &lt;input type="submit" name="send1"&gt;
          &lt;/form&gt;
  
          &lt;br&gt;
      &lt;/center&gt;
  
      &lt;?php
          if (isset($_POST['send1'])) {
  
              $msg_post = $_POST['msg_form'];
  
              echo "&lt;center&gt; $msg_post &lt;/center&gt;";
              fwrite($port, "$msg_post");
          }
  
          fclose($port);
      ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>