Connecting to GSM/GPRS unstable, eventually hangs

Managed to solve the problem - I think it was due to not having enough space to store a long String!
I have re-written the code to put everything in a function call and made things a bit neater;

/*
  SendTemp30mins_v2
 
 This sketch connects to the foobar.com website through a GSM shield.
 
 Circuit:
 * GSM shield attached to an Arduino
 * SIM card with a data plan
 * Temperature sensor on Pin A0
 
 */

// libraries (Use with modified library!)
#include <GSM.h>

 // PIN Number
 #define PINNUMBER ""

 // APN data
 #define GPRS_APN       "internet.com" // your GPRS APN
 #define GPRS_LOGIN     "wapuser1"    // your GPRS login
 #define GPRS_PASSWORD  "wap" // your GPRS password

 // initialize the library instance
 GSMClient client;
 GPRS gprs;
 GSM gsmAccess; 

void setup()
{
  // initialize serial communications
  Serial.begin(9600);
}

void loop()
{
  // read temperature sensor
  String sensorValueString = String(analogRead(A0), DEC);
    
  // put reading into path
  String path = String("/data/test.php?temperature_1=" + sensorValueString + "&temperature_2=0"); 

  // send result to server
  String uploadResult;
  uploadResult = uploadReading(path);
  Serial.println(uploadResult);
  
  // wait for half an hour (less 60s to account for communication)
  if (uploadResult == "OK")
  {
    Serial.println("29 minutes delay....");
    delay(1680000); // 28 minutes
  }
  delay(60000); // 1 minute 
}

String uploadReading(String path)
{
  String uploadReturnStatus;

 // URL and port
 char server[] = "foobar.com";
 int port = 80; // port 80 is the default for HTTP

  // Start the modem with GSM.begin()
  Serial.println("Connecting GSM.");
  // Retry 5 times before giving up
  unsigned loopCntGSM = 5;
  while(loopCntGSM--)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
    {
      Serial.println("GSM connected.");
      break;
    }
    else
    {
      Serial.println("GSM not connected.");
      delay(1000);
    }
    if(!loopCntGSM)
    {
      Serial.println("GSM connection failed.");
      uploadReturnStatus = "GSM_FAIL";
      return uploadReturnStatus;
    }  
  }
  
  // attach the shield to the GPRS network with the APN, login and password
  Serial.println("Connecting GPRS.");
  // Retry 5 times before giving up
  unsigned loopCntGPRS = 5;
  while(loopCntGPRS--)
  {
    if(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY)
    {
      Serial.println("GPRS connected.");
      break;
    }
    else
    {
      Serial.println("GPRS not connected");
      delay(1000);
    }
    if(!loopCntGPRS)
    {
      Serial.println("GPRS connection failed.");
      Serial.println("Terminating GSM");
      gsmAccess.shutdown();
      uploadReturnStatus = "GPRS_FAIL";
      return uploadReturnStatus;
    }   
  }

  // Connect to the server and send readings
  if (client.connect(server, port))
  {
    Serial.println("Connected to server.");
    // Make a HTTP request:
    client.print("GET ");
    client.print(path);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("Connection: close");
    client.println();
  } 
  else
  {
    Serial.println("Server connection failed");
    Serial.println("Terminating GSM");
    gsmAccess.shutdown();
    uploadReturnStatus = "SERVER_FAIL";
    return uploadReturnStatus;
  }

  // Read incoming server response
  String outputString = "";
  while (client.available() || client.connected())
  {
    // if there are incoming bytes available from the server, read them
    if (client.available())
    {
      char c = client.read();
      outputString = outputString + c;
      if (outputString.length() > 15)
      {
        // stop the client.
        Serial.println("Disconnecting from server.");
        client.flush();
        client.stop();
        break;
      }
    }
  }
  Serial.println("Server response;");
  Serial.println(outputString);
  
  Serial.println("Terminating GSM");
  gsmAccess.shutdown();
  
  // check server response for 200 OK
  if (outputString.startsWith("HTTP/1.1 200 OK"))
  {
    uploadReturnStatus = "OK";
    return uploadReturnStatus;
  }
  uploadReturnStatus = "RESPONSE_FAIL";
  return uploadReturnStatus;
}

which gives the response;

Connecting GSM.
gsm.begin()
gsm.begin() waiting for ready
GSM connected.
Connecting GPRS.
GPRS connected.
Connected to server.
Disconnecting from server.
Server response;
HTTP/1.1 200 OK

Terminating GSM
OK
29 minutes delay....

I will leave this running for a few days and see if it is really working as it should.....