Sensor not updating when using Ethernet Shield

I’m using this example for my ethernet shield

It works fine on its own, but I’m getting some strange behavior when I modify the code to update my sensor values instead of just updating the analog in pins.

void loop(){                                                                   //here we go....
char tmp[25];
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    boolean print = 1;
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c =;
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          //client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println("<!DOCTYPE HTML>");
 //code I added       
    while (pHserial.available()) {                                               //while a char is holding in the serial buffer 
         char inchar = (char);                                  //get the new char
         pHstring += inchar;                                               //add it to the sensorString
         if (inchar == '\r') {pH_stringcomplete = true;}                   //if the incoming character is a <CR>, set the flag
if (pH_stringcomplete){                                                   //if a string from the Atlas Scientific product has been recived in its entierty 
      pHstring = "";                                                       //clear the string:
      pH_stringcomplete = false;                                           //reset the flag used to tell if we have recived a completed string from the Atlas Scientific product
 //end code I added  
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
    // give the web browser time to receive the data
    // close the connection:
    Serial.println("client disconnected");

I need to send ‘r’ over the software serial port to my pH probe to get it to read data to me. This works the first time I load the code onto the arduino. When I refresh the webpage (going to in my browser and refreshing), my sensor isn’t updating. It works the first time through the loop, but after that, the pHserial port never seems to become ‘available’ again. (The pHserial port must be available for the arduino to get data back from the sensor.)

Any idea why this works one time and then isn’t available again?

Any idea why this works one time and then isn't available again?

It would help if you posted all the code but it sounds like you are running short of SRAM. Try moving those print strings into flash memory with the F command.

How many instances of SoftwareSerial do you have? If you only have one, then it is not necessary to call the listen() method.

You should separate getting the pH level from the responding to the client. Getting the pH level, which appears to take time, only when the client ask for it is wrong. When the client asks, you should immediately send the last reading.