NYCPHP Meetup

NYPHP.org

[nycphp-talk] [PHP] Fwd: Code Optimization Help

Joseph Crawford codebowl at gmail.com
Tue Sep 20 11:40:06 EDT 2005


Ok so finally i implemented my logging class into my mail merge object, this 
is the results

Word -> Application Opened.
Word -> Document1 Document Added.
Word -> header.doc Document Saved.
Word -> header.doc Document Closed.
Word -> Document2 Document Added.
Word -> ds.doc Document Saved.
Word -> ds.doc Document Closed.
Word -> Has_Site.dot Document Opened.
Word -> Opening Header Source.
F:/htdocs/csaf/data/mailmerge/header.doc File Exists

I threw in a file_exists check to make sure the script was actually seeing 
the file and had the correct path. It does. This is very strange because 
nothing happens, it's like i hit a never ending loop but php never times out 
either. I have my php timeout to 30 seconds yet this has run in excess of 5 
minutes now.

The expected results for the log would look something like this
Word -> Application Opened.
Word -> Document1 Document Added.
Word -> header.doc Document Saved.
Word -> header.doc Document Closed.
Word -> Document2 Document Added.
Word -> ds.doc Document Saved.
Word -> ds.doc Document Closed.
Word -> Has_Site.dot Document Opened.
Word -> Opening Header Source.
F:/htdocs/csaf/data/mailmerge/header.doc File Exists
Word -> Opening Data Source.
Word -> Executing Merge.
Word -> Has_Site.doc Document Saved.
Word -> Has_Site.doc Document Closed.
Word -> Merge Successful.


The code that is hanging is below

private function CreateDocument($template) {
$this->obj->Documents->Open($this->mm_data_dir.'/'.$template.'.dot');
Logger::log('Word -> '.$this->obj->ActiveDocument->Name().' Document 
Opened.');

Logger::log('Word -> Opening Header Source.');
if(file_exists($this->mm_data_dir.'/header.doc')) {
Logger::log($this->mm_data_dir.'/header.doc File Exists');
}
// THIS IS THE LINE THAT HANGS, THE FILE EXISTS AND IS POPULATED THE FILE 
CONTENTS CAN BE SEEN HERE
http://codebowl.dontexist.net/bugs/MailMerge/3.jpg$this->obj->ActiveDocument->MailMerge->OpenHeaderSource($this->mm_data_dir.'/header.doc');
Logger::log('Word -> Opening Data Source.');
$this->obj->ActiveDocument->MailMerge->OpenDataSource($this->mm_data_dir.'/ds.doc');
Logger::log('Word -> Executing Merge.');
$this->obj->ActiveDocument->MailMerge->Execute();
$this->obj->ActiveDocument->SaveAs($this->mm_data_dir.'/'.$template.'.doc');
Logger::log('Word -> '.$this->obj->ActiveDocument->Name().' Saved.'); 
Logger::log('Word -> '.$this->obj->ActiveDocument->Name().' Document 
Closed.');
$this->obj->ActiveDocument->Close();
}

Any help with this would be appreciated. I am not sure why it is choosing to 
hang today ;( I have been going through the COM object API documentation and 
i dont see myself doing anything i shouldnt be doing.

You can see the full code here
http://pastebin.com/369068
that is if it hasnt expired, if so send a reply and i will post again ;)
Thanks in advance

-- 
Joseph Crawford Jr.
Codebowl Solutions, Inc.
1-802-671-2021
codebowl at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20050920/a72d7fe0/attachment.html>


More information about the talk mailing list