Hello, immediately I ask you not to kick much, a newbie in PHP, I am more used to programming in Delphi ...

Actually, the essence of the issue and the problem itself: There is a script that at a certain time receives a large array of strings (300-500) ... in each row there are 2-4 words (small sentence or phrase), the task is to translate all this text into Ukrainian, I use Yandex API ( http://code.google.com/p/translate-api/source/browse/trunk/)

<? include_once 'Yandex_Translate.php'; include_once 'Big_Text_Translate.php'; header('Content-Type: text/html; charset=win-1251'); function GTR($str,$in1,$in2) { $translator = new Yandex_Translate(); $bigText = $str; $textArray = Big_Text_Translate::toBigPieces($bigText); $numberOfTextItems = count($textArray); foreach ($textArray as $key=>$textItem){ $translatedItem = $translator->yandexTranslate($in1, $in2, $textItem); $translatedArray[$key] = $translatedItem; } $translatedBigText = Big_Text_Translate::fromBigPieces($translatedArray); return $translatedBigText; } for ($l = 0; $l <= count($array); $l++) { $text=iconv('windows-1251','utf-8//IGNORE',$array[$l]); $text=iconv('utf-8','windows-1251//IGNORE',GTR($text,'ru','uk')); echo text; } ?> 

but in the end, the error Fatal error: Maximum execution time of 30 seconds exceeded in \ Yandex_Translate.php on line 43

The question is the following, for example, or break this array into small ones and translate it in turn, or make some kind of timeout before each sending a transfer request, in order to translate it normally ...

I will be glad to any advice !!!

    1 answer 1

    The easiest solution is to set the execution time limit for more than 30 seconds!

    Or through the function: set_time_limit(0); (0 - infinite), or in php.ini change the parameter value.

    • in php.ini it will not be possible to change it, since the script will be used by different people on different servers and hosting ... I tried to form the required result from the array right away (output format (not an array but a big string)) but when sent for translation it gives a Request error uri too large (Request (uri too large)). although the translation class itself should easily translate large texts as described and shown in the API documentation ... - arashvg
    • Request uri too large === too long string of GET parameters - Zowie