CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Odd behavior with civicrm_initialize(TRUE);
Pages: [1]

Author Topic: Odd behavior with civicrm_initialize(TRUE);  (Read 2380 times)

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Odd behavior with civicrm_initialize(TRUE);
February 16, 2009, 07:04:19 am
I am on Drupal 6 and CiviCRM 2.1. I have a block that pulls up a bunch of CiviEvents and orders them by date. It's been working fine for quite some time. Today I noticed when I submit certain pages or go to certain pages I get the white screen of death. However, no errors are in my apache logs or drupal logs. And when I do a simple refresh, the page then loads fine.

After about 2 hours of troubleshooting this, I deduced that it is related to my block of CiviEvents. Specifically, it is the call to   

civicrm_initialize(TRUE);

If I remove this line, the problem goes away. As soon as I put it back, it starts happening again. I have no idea why this would be causing a problem so suddenly. Can anyone help? The full code I use is below, but like I said it is specific to the initialize function.

Code: [Select]
<?php
$dated_events 
= array();
if (
module_exists('civicrm')) {
  
civicrm_initialize(TRUE);
  require_once 
'api/v2/Event.php';
  
  
// This example limits listing to public and active events
  
$params = array ('is_public'     => 1, 'is_active'     => 1);
  
$myEvents = civicrm_event_search( $params );
  
  if (
$myEvents) {
    
$count = 0;
    
    
// Call the sorting function
    
usort($myEvents,'cctv_civicrm_get_start_date');
    foreach (
$myEvents as $event) {
      
$now = time( );
  // print_r($event);
      // Need to format the event end date in unix time, so we call a CiviCRM helper function
      
$endDate = CRM_Utils_Date::unixTime( $event['end_date'] );  
      
$startDate = CRM_Utils_Date::unixTime( $event['start_date'] );  

      
// We want to show any events whose end dates have not passed
      
if ( $now <= $endDate ) { 
        
        
// Now we format the event start and end dates again to be user-friendly
        
$startdate = date('n/j',strtotime($event['start_date']));
        
$enddate = date('n/j',strtotime($event['end_date']));
        
        if(
$startdate != '1/1' && $enddate != '12/31'){
        
// if it's a date range, we need to show both start/end dates; otherwise just show start
        
if($startdate != $enddate){
          
$finaldate = $startdate." - ".$enddate;
        }
        else{
          
$finaldate = $startdate;
        }
      
        
$eventid = $event['id'];
        list(
$title_place, $title_desc) = split(":",$event['title'],2);
     
        
array_push($dated_events, array('eventDate'=> $finaldate, 'eventTitle' => $title_place.' '.$title_desc, 'eventPath' => 'civicrm/event/info', 'eventQuery' => 'reset=1&id='.$event['id']));
        
        
// Increase the counter so we can know when to stop
        
$count++;
        }
        
// Once we reach 10 events, stop
        
if ($count > 9) break;
      } 
// End if $now <= $endDate 
    
} // End foreach
   
  
} 
} 
// End if CiviCRM exists

?>

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Odd behavior with civicrm_initialize(TRUE);
February 16, 2009, 09:53:41 am
Also, in IE7, I get a HTTP 500 Internal Server Error page instructing me to try refreshing the page when this happens.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Odd behavior with civicrm_initialize(TRUE);
February 16, 2009, 01:13:53 pm

The white screen of death and the http 500 error indicates that it is a php error. most likely php is aborting OR you are hitting the memory limit

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Odd behavior with civicrm_initialize(TRUE);

This forum was archived on 2017-11-26.