Monday 15 February 2010

performance - PHP script slow on server, but fast in local -


First of all, I want to say my English is very bad, but I am going to try.

I have tried to run the PHP script on the Vamp server on my PC and it works fine, but when I upload it, for some reason, it is enough to complete the execution on the host Spends time, and almost always ends with a service Temporarily unavailable error (turn off the host connection)

I have used some die (to see where the problem is) And I came to know that It's for a loop where I'm making a big string (I'm just trying to make a bigger INSERT to execute it after the loop) and this loop works in local ... I do not understand Why is not it working on the host?

  // Insert values ​​BDD $ sql = "Insert in heroic values"; $ Primer = 1; $ Tiempo_inicio = Microtom (true); ($ I = 0; $ i & lt; = count ($ array2) - 1; $ i ++) {// Dadar Glucosa If ($ $ Array2 [$ i] [1] == "") {if ( ! $ Primer) $ sql = ","; Rest $ primer = 0; $ Sql = "('". $ This- & gt; paciente. "', '". $ Array2 [$ i] [0].' ',' Glucosa ', ". $ Array2 [$ i] [1]." ) "; $ The-> Comprobar_Aumentar_Avisos ($ array2 [$ i] [0], $ array2 [$ i] [1]);} // insert raciones if (! $ Array2 [$ i] [2] == "") {If (! $ Primer) $ sql. = ","; Rest $ primer = 0; $ sql. = "('. $. $ This- & gt; paciente.' ','". $ Array2 [$ I] [0]. '', 'Racinus', ". $ Array2 [$ i] [2].") "; } // Inser insulin if ($ $ array $ [$ i] [3] == "") {if ($ $ primer) $ sql = "," ;; Rest $ primer = 0; $ Sql = "('". $ This- & gt; paciente. "', '". $ Array2 [$ i] [0].' ',' Insulina ', ". $ Array2 [$ i] [3]." ); $} Tiempo_total = Microtim (true) - $ typo_inicoo; die ($ tiempo_total); if ($ sql! = "Insert in hero values") {$ AccessBD = new TAccessBD; $ accessbid-> USURIO = $ This- & gt; Prineate; $ AccessBD-> Inicialitzar_BD (); $ accessbid-> query = $ sql; $ Res = $ AccessBD-> Ejecutar_SQL (); $ AccessBD-> Finalitzar_BD (); Not set ($ AccessBD);}    

The problem was that the loop I was reaching the database many times this time Function: $ this-> Comprobar_Aumentar_Avisos ($ array2 [$ i] [0], $ array2 [$ i] [1]);

Local I There is no problem due to this, but also on the server, along with the database in other external hosts, it was very slow.

So I can reduce the number of access to at least the minimum database And now it's working fine.

Thank you very much for the help!

No comments:

Post a Comment