I made a daily batch process which insert french (or other languages) data in my database after translating it to English with the Google Translation API. When I use it in a local environment, there is no problem. However, when this process is executing in production, it stops before the end. Do you have an idea about the problem ? Is there a parameter to change in my Google Translation API account?
For example, this morning, process stops at line 54 :
my file :
53 Ce code promo vous fait gagner 12% de remise sur les articles de la catégorie sacs multifonctions. C'est pour vous!,12% de réduction Newchic,12% de réduction Newchic,Newchic,newchic,1534118399,code,HOMEBAG12,http://tc.tradetracker.net/?XXXXXXXXXXXXXXXXXX=
54 Newchic vous offre avec ce code réduction; 15% de remise sur les articles de la catégorie animal de compagnie. Ne ratez pas cette offre!,15% de réduction Newchic,15% de réduction Newchic,Newchic,newchic,1534291199,code,PETDOG15,http://tc.tradetracker.net/?XXXXXXXXXXXXXXXXXX=
55 Découvrez les offres en cours sur le site et gagnez 10% de remise sur les articles de la catégorie vêtements de maternité. Offre valable grâce au code promo. Profitez-en!,10% de réduction Newchic,10% de réduction Newchic,Newchic,newchic,1534636799,code,MOM2018,http://tc.tradetracker.net/?XXXXXXXXXXXXXXXXXXXXX=
My program :
$apiKey = 'XXXXXXXXXXXXXXXXXXXX';
while($tab=fgetcsv($file,2048,',')){
.....
$result=$this->language_curl($apiKey,$text);
$exclude_list=array("en","und","","erreur");
if (!in_array($result, $exclude_list)){
$translate_title=$this->translate_curl($apiKey,$title,$result);
$translate_content=$this->translate_curl($apiKey,$content,$result);
$content=$translate_content;
$title=$translate_title;
}
....
insert database
....
end while
...
function language_curl($apiKey,$text){
$url = 'https://www.googleapis.com/language/translate/v2/detect?key=' . $apiKey . '&q=' . rawurlencode($text);
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
$responseDecoded = json_decode($response, true);
$responseCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
if($responseCode != 200) {
$return = "erreur";
}
else {
$return = $responseDecoded['data']['detections'][0][0]['language'];
}
return $return;
}
function translate_curl($apiKey,$text,$result){
$url = 'https://www.googleapis.com/language/translate/v2?key=' . $apiKey . '&q=' . rawurlencode($text) . '&source=' . $result . '&target=en';
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($handle);
$responseDecoded = json_decode($response, true);
curl_close($handle);
return $responseDecoded['data']['translations'][0]['translatedText'];
}