Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Translate Curl Using Up All Memory in php 5.3.8

I have been using this to translate basic site text in to different languages. It has worked great until I updated to PHP 5.3.8. It completely took down my server by using up all the memory. What am I doing wrong? I'm sure by saying that I'll get a lot of comments :)

try {
    $gt = new Gtranslate;
    $gt->setRequestType('curl');

    $SQL    = "SELECT * FROM PAGE_CONTENT WHERE live_page = '1'";
    $result = mysql_query($SQL);
    while ($row = mysql_fetch_array($result)) {
        $page_id_sub    = $row["page_id"];
        $page_title     = $row["page_title"];
        $page_permalink = $row["page_permalink"];

        if (empty($mylang)) {
            echo "<a href='/$permalink/$page_permalink.html'>$page_title</a> |";
        } else {
            $page_trans = $gt->$mylang("$page_title");
            echo "<a href='/$permalink/$page_permalink.html'>$page_trans</a> |";
        }
    }
} catch (GTranslateException $ge) {
    echo $ge->getMessage();
}
like image 620
MHowey Avatar asked Oct 26 '11 01:10

MHowey


1 Answers

I would debug like this in order to check which process stuck.

<?php

echo "\n start: " . memory_get_usage() . "\n";

  try{
    $gt = new Gtranslate;
    $gt->setRequestType('curl');

    echo "\n after class: " . memory_get_usage() . "\n";

    $SQL = "SELECT * FROM PAGE_CONTENT WHERE live_page = '1'";
    $result = mysql_query( $SQL );

    echo "\n after query: " . memory_get_usage() . "\n";

    while( $row = mysql_fetch_array( $result ) ) {
      $page_id_sub = $row["page_id"];
      $page_title = $row["page_title"];
      $page_permalink = $row["page_permalink"];

      if(empty($mylang)){
         echo "<a href='/$permalink/$page_permalink.html'>$page_title</a> |";
      }
      else {
         $page_trans = $gt->$mylang("$page_title");
         echo "<a href='/$permalink/$page_permalink.html'>$page_trans</a> |";
      }
    }
    echo "\n after while: " . memory_get_usage() . "\n";

  }
  catch (GTranslateException $ge){
    echo $ge->getMessage();
  }

echo "\n end: " . memory_get_usage() . "\n";
like image 55
James M. Avatar answered Nov 10 '22 06:11

James M.