First I want to say that my english is very poor, but I'm going to try.
I've tried to run a PHP script on my PC with wamp server and it works ok, but when I upload, for some reason, it spends so much time to complete the execution on the host, and almost always ends with a Service Temporarily Unavailable error (the host close the connection).
I've used some die() to see where is the problem and I found it's a for loop where I'm making a big string (I'm only concatenating to make a big INSERT for executing it after the loop). And this loop works in local... I can't understand why is not working on the host.
//insertar valores en bbdd
$sql = "Insert into valor values ";
$primer = 1;
$tiempo_inicio = microtime(true);
for($i = 0 ; $i <= count($array2) - 1 ; $i++)
{
//insertar glucosa
if(!$array2[$i][1] == "")
{
if (!$primer) $sql .= ", ";
else $primer = 0;
$sql .= "('" . $this->paciente . "', '" . $array2[$i][0] . "', 'Glucosa', " . $array2[$i][1] . ")";
$this->Comprobar_Aumentar_Avisos($array2[$i][0], $array2[$i][1]);
}
//insertar raciones
if(!$array2[$i][2] == "")
{
if (!$primer) $sql .= ", ";
else $primer = 0;
$sql .= "('" . $this->paciente . "', '" . $array2[$i][0] . "', 'Raciones', " . $array2[$i][2] . ")";
}
//insertar insulina
if(!$array2[$i][3] == "")
{
if (!$primer) $sql .= ", ";
else $primer = 0;
$sql .= "('" . $this->paciente . "', '" . $array2[$i][0] . "', 'Insulina', " . $array2[$i][3] . ")";
}
}
$tiempo_total = microtime(true) - $tiempo_inicio;
die($tiempo_total);
if ($sql != "Insert into valor values ") {
$AccessBD = new TAccessBD;
$AccessBD->usuario = $this->paciente;
$AccessBD->Inicialitzar_BD();
$AccessBD->query = $sql;
$res = $AccessBD->Ejecutar_SQL();
$AccessBD->Finalitzar_BD();
unset($AccessBD);
}
!($array2[$i][1] == "")instead of!$array2[$i][1] == ""$array2?echo time()." Start processing value ".$i."\n";echo time()." End processing value ".$i."\n";end then try to figure out where bottle neck is. Some providers are limiting the database connection speed available on certain conditions (too much query in few minutes, allowed banda connection overquota, ...) Let us know!