// create client object
$soapclient = new SoapClient($serverpath, array("trace" => 1));
$soapclient->timeout = 500;
$soapclient->response_timeout = 500;
//set soap Action
$method = 'GetAllEvents';
$soapAction = $namespace . $method;
$num_events_returned = 0;
$eventRank = 2000;
$method = 'GetAllEvents';
$param = array('SecurityToken' => "{$securitytoken}");
print_message("Invoking {$method} web method.....");
# 6/29 Jassene commented out was taking too long
#$result = $soapclient->call($method,$param,$namespace,$soapAction);
try {
    $result = $soapclient->GetAllEvents($param);
    print_message("Done Calling {$soapAction}.");
    $xmlString = preg_replace("/(<\\/?)(\\w+):([^>]*>)/", "\$1\$2\$3", trim($soapclient->__getLastResponse()));
    try {
        libxml_use_internal_errors(true);
        $soap_root = new SimpleXMLElement($xmlString);
        $data = $soap_root->soapBody->GetAllEventsResponse->GetAllEventsResult->ROOT->DATA;
        foreach ($data->row as $event) {
            $attrib = $event->attributes();
            $num_events_returned++;
            $eid = $attrib->EventID;
            $raw_ename = $attrib->EventName;
            $ename = mysql_escape_string($attrib->EventName);
            $etypeid = $attrib->EventTypeID;
            $cid = $attrib->CategoryID;
            InsertIntoEvents_temp($eid, $ename, $raw_ename, $etypeid, $cid, $eventRank);