Hey everyone, I am using the Zend_GData Package to connect to a Google
Calendar and do various things such as add/edit/delete events.
However, I find that these are pretty expensive operations, and can
sometimes take a visible 4 seconds to complete. I was wondering if
there is anything I can do to optimize my code and make it faster?
Here is an example of my add function:
function add_gcal($title, $date, $where, $desc){
$newIncludePath = array();
$newIncludePath[] = '../ZendGdata-1.8.4PL1/library';
$newIncludePath = implode($newIncludePath);
set_include_path($newIncludePath);
// load classes
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Http_Client');
// connect to service
$user = "***[email protected]";
$pass = "*******";
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass,
$service);
try {
$gdataCal = new Zend_Gdata_Calendar($client);
$newEvent = $gdataCal->newEventEntry();
$newEvent->title = $gdataCal->newTitle($title);
$newEvent->where = array($gdataCal->newWhere($where));
$newEvent->content = $gdataCal->newContent("$desc");
$when = $gdataCal->newWhen();
$when->startTime = $date;
$when->endTime = $date;
$newEvent->when = array($when);
$createdEvent = $gdataCal->insertEvent($newEvent);
return $createdEvent->id->text;
} catch (Zend_Gdata_App_Exception $e) {
return NULL;
}
}
I tried setting the $client connection once upon login, and storing
$client as a SESSION variable that I could then re-use each time I
need to do an operation on the calendar. This doesn't seem to work, I
get the following Zend_GData_App_Exception:
exception 'Zend_Gdata_App_HttpException' with message 'Argument is not
an instance of Zend_Http_Client.'
in /home/content/b/e/h/behrk2/html/ZendGdata-1.8.4PL1/library/Zend/
Gdata/App.php:247
Stack trace:
#0 /home/content/b/e/h/behrk2/html/ZendGdata-1.8.4PL1/library/Zend/
Gdata/App.php(172):
Zend_Gdata_App->setHttpClient(Object(__PHP_Incomplete_Class),
'MyCompany-MyApp...')
#1 /home/content/b/e/h/behrk2/html/ZendGdata-1.8.4PL1/library/Zend/
Gdata.php(107):
Zend_Gdata_App->__construct(Object(__PHP_Incomplete_Class),
'MyCompany-MyApp...')
#2 /home/content/b/e/h/behrk2/html/ZendGdata-1.8.4PL1/library/Zend/
Gdata/Calendar.php(87):
Zend_Gdata->__construct(Object(__PHP_Incomplete_Class),
'MyCompany-MyApp...')
#3 /home/content/b/e/h/behrk2/html/scripts/functions.php(85):
Zend_Gdata_Calendar->__construct(Object
(__PHP_Incomplete_Class))
#4 /home/content/b/e/h/behrk2/html/calendar/modify_duty.php(68):
add_gcal(Object(__PHP_Incomplete_Class), 'R4 - Stephen Au...',
'2009-08-19', 'Building: Liva ...', 'Primary')
#5 {main}
Finally, I tried using keepalive:
// connect to service
$user = "[email protected]";
$pass = "154Kmb";
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass,
$service);
$client->setConfig(array('keepalive' => true));
...But, I'm not sure how to properly use this (in terms of where and
when), because each time this function gets called, wouldn't a new
connection be made?
Any ideas? Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---