Page 1 of 1

PHP Translator help please

Posted: Wed Jul 27, 2011 3:19 am
by hackerspk
i am a newbie i make this code for word to word translation it works fine until my dictionary is under 50000 words but now it given error time out if there is any way to make this code better? thanks in advance
Error:  Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\salar\engine\modules\show.full.php on line 623

Code

Code: Select all

$user_name = "root";
$password = "";
$database = "salar";
$server = "127.0.0.1";

$mydata = "text to translate";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
   $SQL = "SET NAMES 'utf8'";
   $SQL = "SELECT * FROM dle_roman ORDER BY LENGTH( roman ) DESC";
   $result = mysql_query($SQL);
   while ($db_field = mysql_fetch_assoc($result)) {
      $mydata = str_replace ($db_field['urdu'],$db_field['roman'],$mydata);
   }
   echo $mydata;
   mysql_close($db_handle);
} else {
   print "Database NOT Found ";
   mysql_close($db_handle);
}

Re: PHP Translator help please

Posted: Wed Jul 27, 2011 4:06 am
by Benjamin
If this isn't something you're running often, just change the time limit. Have a look at http://br2.php.net/manual/en/function.s ... -limit.php

Re: PHP Translator help please

Posted: Wed Jul 27, 2011 8:35 am
by hackerspk
if i increase time limit it would be very rough for every one to wait 2 or 3 minutes for each translation

Re: PHP Translator help please

Posted: Wed Jul 27, 2011 1:01 pm
by Benjamin
How may fields are in the table?

Why not store the results of the following line of code in the table itself?

Code: Select all

$mydata = str_replace ($db_field['urdu'],$db_field['roman'],$mydata);
You'll probably want to store the output in a cache file for up to an hour or so, depending on how often the data changes. Then just display the cache file instead of executing the code.

Re: PHP Translator help please

Posted: Thu Jul 28, 2011 6:01 am
by hackerspk
there are 2 fields
urdu,roman
because mydatabase is very big if i store these results then i need to buy extra mysql storage

Re: PHP Translator help please

Posted: Thu Jul 28, 2011 6:59 am
by Weirdan
how long (typically) is the string you have in $mydata variable?

Re: PHP Translator help please

Posted: Fri Jul 29, 2011 4:38 am
by hackerspk
more than 2000 words less then 10 words

Re: PHP Translator help please

Posted: Fri Jul 29, 2011 6:57 am
by Weirdan
I'd suggest to export the wordlist to a php array, store that somewhere in a file and include that file. Assuming you have opcode cache the loading latency should be pretty low. Of course you'd need to regenerate the file when your database changes.