Home · Links · Contact Us
Home arrow Forums
Home
Features
FAQ
Screen Shots
Modules
Themes
Demos
Documentation
Forums
Contact Us
Download
Purchase
Quotes

" ... I want to tell you that your thyme product is functional and valuable beyond words. I cannot imagine why any portal would be without it. It is the cornerstone of our new project ..."

" ... Thanks for such a complete project, its making my job much easier. ..."

" ... I have now deployed 4 different calendars and our users love them ... "

" ... Easy to install and use and a great look/design. ..."

" ... This has to be the easiest to use program I think I've had to deal with at all this year. ..."


  FAQFAQ    SearchSearch  RegisterRegister   Log inLog in 
Memory Error

 
Post new topic   Reply to topic     Forum Index -> Modules
View previous topic :: View next topic  
Author Message
jgulledge19



Joined: 13 Aug 2007
Posts: 6

PostPosted: Mon Aug 13, 2007 8:29 pm    Post subject: Memory Error Reply with quote

I have made a custom import Module to import all class schedules into the Thyme Calendar. Part of the import process I check to see if the classes/event conflict and I populate exclude date. The problem is that it the memory is not being released somewhere it so it runs out of memory. I don't know for sure but I believe it has to do when I am calling on the repeat class and/or the matrix class. Here is the code where the memory leak is occurring:

Code:

//$_cal_sql = new $_cal_sql;
##########################
#
### LOCATION CONFLICTS
#
##########################
if($e->location_id) {
   $_location_result = $_cal_sql->query("SELECT check_conflict, name, id FROM {$_cal_dbpref}locations
      WHERE id='".$e->location_id."' ");
   $_location_result[0]['check_conflict'];
   // this is to allow a location the option of weather or not to check for conflicts
}

if($e->location_id )
{
   unset($conflicts); unset($tmp_create); unset($create_ex);
   $conflicts = array();
   $tmp_create = array();
   $create_ex = array();
   
   if(!$exclude)
   {
      $exclude[1]['all']=0;
   }
   # Repeating events
   #####################
   if($e->freq > 0)
   {
   //echo 'LINE 475! Start Repeat Event';
      
      $_actual_start =  /* this is to store the real start to allow overriding of the starttime */
      $e->start_timestamp = $e->start = $e->starttime;
      
      $e->end = $e->endtime;
      
      $r = new _cal_repeater($e);
      
      # get next time event will happen
      $n = $r->get_next_time(_ex_date("Y-n-j 0:0", $e->starttime), false,
         $e->starttime);

      # set start time to next time
      if($n !== null) {
         $e->starttime = _ex_strtotime($n . _ex_date(" H:i:0",
            $e->starttime), true);
      }
      
      # if they do not match
      if($e->next != $e->starttime) $e->next = $e->starttime;
      
      # end after
      if(intval($e->end_after) > 0 && !$e->endtime) {
         $e->endtime = $r->get_last_time();
      }
      
      # set maximum date to go..
      ###########################
      list($y,$m,$d) = explode('-',_ex_date("Y-n-j", $e->starttime));
      $max_check = _ex_mktime(0,0,0, ($m + _CAL_LOCATION_CONFLICT_MONTHS_), $d, $y);
      //echo 'Max: '.$max_check;
      
      # _cal_event_matrix($time, $view = null, $etypes = 0, $cal = 0, $filter="")
      unset($em);
      $em = new _cal_event_matrix($e->starttime, 'day', 0, $e->calendar,
             "location_id = {$e->location_id} AND {$_cal_dbpref}Events.id != " . intval($e->id));
      $now = ($e->starttime - ($e->starttime % 86400));
      $event_starttime = $e->starttime;
      list($d_h,$d_m) = explode(':',$e->duration);
      $event_endtime = $event_starttime + ($d_h * 3600) + ($d_m * 60);
      $event_duration = ($d_h * 3600) + ($d_m * 60);
   
      while($now < $max_check && (!$e->endtime || ($now endtime)))
      {
         
         $s_time = $e_time = NULL;
         if( $exclude[$now]['time'] > 0)
         {
            $s_time = intval($now + $exclude[$now]['time'] );
            $e_time = intval($now + $exclude[$now]['time'] + $exclude[$now]['duration']);
         }
         $tmp_ex_type = $exclude[$now]['ex_type'];
         if( $exclude[$now]['ex_type'] == 'All')
         {
            $tmp_ex_type = $e->etype;// to compare to every date
         }
         if(
            ( $exclude[$now]['all'] == 1 ||
               ( //overlapping start
                  ( ($event_starttime >= $s_time) && $event_starttime < $e_time )
                           || //overlapping end
                  ( ($event_endtime > $s_time) && $event_endtime etype
            )// end if ")" */
         {
            //enter the excluded date
            $create_ex[] = $now;
         }
         elseif($_location_result[0]['check_conflict'] != 'Yes')
         {
            //continue - don't check for conflicts
         }
         //preventing error message - and make sure not excluded
         elseif( count($em->matrix[0]) > 0 && !in_array($now,$tmp_create) )
         {
            foreach($em->matrix[0] as $ev)
            {
               # Allday events conflict with everything
               if($ev['allday'] || $e->allday)
               {
                  $conflicts[] = $ev;
                  unset($ev);
                  if($print_conflicts == 'no')
                  {
                     break;
                  }
                  continue;
               }
               list($d_h,$d_m) = explode(':', $ev['duration']);
               $ev['end'] = $ev['start'] + ($d_h * 3600) + ($d_m * 60);
               
               if(       //overlapping start
                     ( ($event_starttime >= $ev['start']) && $event_starttime < $ev['end'] )
                              || //overlapping end
                     ( ($event_endtime > $ev['start']) && $event_endtime get_next_time( _ex_date("Y-n-j 0:0", $now ), false );
      
         # event stopped repeating?
         if($n == null)
         {
            $now = $now + $max_check + 1;
            /* this is to restore the real starttime */
            $e->start_timestamp = $e->start = $e->starttime = $_actual_start;
         }
         else
         {
            $create_matrix = 'No';// do not restart
            # set start time to next time
            $now = _ex_strtotime($n . " 0:0:0", true);
            unset($em);
            $em = new _cal_event_matrix($now, 'day', '0', $e->calendar,
            "location_id = {$e->location_id} and {$_cal_dbpref}Events.id != " .
            intval($e->id));
            
            $event_starttime = $now + ($e->starttime % 86400);
            $event_endtime = $event_starttime + $event_duration;
         
         }
      }
   }
   # Non-repeating events
   #########################
   else
   {
      $em = new _cal_event_matrix($e->starttime, 'day', 0, $e->calendar,
            "location_id = {$e->location_id} and {$_cal_dbpref}Events.id != " .
            intval($e->id));
      $event_starttime = $e->starttime;
      if($e->duration != NULL)
      {
         $tmp_dur = explode(":", $e->duration);
         $dur = $tmp_dur[0]*3600 + $tmp_dur[1]*60 + $tmp_dur[2];
         $event_endtime = $e->starttime + $dur;
      }
      if( count($em->matrix[0]) > 0 )//preventing error message
      {
         foreach($em->matrix[0] as $ev) {
      
            # Allday events conflict with everything
            if($ev['allday'] || $e->allday)
            {
               $conflicts[] = $ev;
               if($print_conflicts == 'no')
               {
                  break;
               }
               continue;
            }
      
            list($d_h,$d_m) = explode(':', $ev['duration']);
            $ev['end'] = $ev['start'] + ($d_h * 3600) + ($d_m * 60);
      
            # check times
           if(       //overlapping start
                  ( ($event_starttime >= $ev['start']) && $event_starttime < $ev['end'] )
                           || //overlapping end
                  ( ($event_endtime > $ev['start']) && $event_endtime query("SELECT id, title
         FROM {$_cal_dbpref}Calendars");
      $cal_a = array();
      
      for($i = 0; $i < count($_cal_title); $i++)
      {
         //putting the SQL results in a differant array
         $cal_a[$_cal_title[$i]['id']] = $_cal_title[$i]['title'];
      }
      $text = '
      
      There is(are) a conflicting event(s), will revise your event.
         Conflicting Events:
         ';

      foreach($conflicts as $ev)
      {
         /* ALL DAY */
         if($ev['allday'] == 1)
         {
            $time_text = 'All day';
         }
         else
         {
            list($dr_h,$dr_m) = explode(":", $ev['duration']);
            //$events[$i]->ends_at
            $start_time = $ev['start'];//$event_matrix[$i]['starttime'];
            $end_time = $start_time + $dr_h*3600 + $dr_m*60;
            $time_text = _ex_date("g:i a",$start_time ).' - '.   _ex_date("g:i a",$end_time );
         }
         $error_text .= ''. _ex_date("D n/j/y ", $ev['start']).'('.$time_text.') 
         '.$ev['title'].' &mdash; Calendar: '.$cal_a[$ev['calendar']].'';
      }
      $error_text .= '
      
      
      ';
   }
   elseif(count($conflicts) &&  $print_conflicts == 'no')
   {
      $error_text .= ''.$e->title.' added to TBA Location.';
      $e->notes .= " -- Desired Location: ".$_location_result[0]['name'];
      $e->location_id = 74;// put in TBA Location
   }
}
unset($_location_result);


Thanks for any help
Back to top
View user's profile Send private message
esoft_ian



Joined: 12 Sep 2005
Posts: 5275

PostPosted: Mon Aug 13, 2007 11:33 pm    Post subject: Reply with quote

This is really hard to do anything with outside of context. Don't bother using unset() and =NULL to try to free memory. PHP will not actually return it to the OS. I'm thinking this may be the issue:

while($now < $max_check && (!$e->endtime || ($now endtime)))

in the 2nd half, I think you want $now < $e->endtime

barring that.. can you throw some echo/debug statements somewhere to see what is going on?
Back to top
View user's profile Send private message Visit poster's website
jgulledge19



Joined: 13 Aug 2007
Posts: 6

PostPosted: Tue Aug 14, 2007 6:13 pm    Post subject: Found a way around it. Reply with quote

I could not track down the memory leak. I have PHP 5.2.3 and I tried using: memory_get_usage() to get an idea, that where it seems to point to the code I have above where the leak is. Here are some articles I found:
http://www.zend.com/forums/index.php?t=msg&goto=12124&S=1c43f3659a91c247cfaf1ea31e2887e2
http://forums.devnetwork.net/viewtopic.php?p=401952
http://devzone.zend.com/manual/zend.layout.html, that maybe could help lead to a solution on it, but I found a different method.

I made a tmp table and the DB and I imported all of the events from the CSV and then I only import 10 at a time from the tmp table and then I use a javaScript page refresh until it is finished. Then it makes a report on what was inserted and what was conflicting.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Modules All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
© 2005 eXtrovert software unless otherwise noted. All rights reserved.
Portions © 2004 Ben Brown. All rights reserved.
Trademarks are property of their respective owners.