|
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. ..."
|
|
| View previous topic :: View next topic |
| Author |
Message |
jgulledge19
Joined: 13 Aug 2007 Posts: 6
|
Posted: Mon Aug 13, 2007 8:29 pm Post subject: Memory Error |
|
|
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'].' — 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 |
|
 |
esoft_ian
Joined: 12 Sep 2005 Posts: 5275
|
Posted: Mon Aug 13, 2007 11:33 pm Post subject: |
|
|
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 |
|
 |
jgulledge19
Joined: 13 Aug 2007 Posts: 6
|
|
| Back to top |
|
 |
|
|
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
|
|
|