Word instance not closing after call to $word->Quit()

Word instance not closing after call to $word->Quit()

am 11.12.2008 10:48:00 von harlequin2

Good morning to you,

one of my scripts creates a winword COM reference, creates a new document, appends data and saves the file to disk; works like a charm, but the word instance remains after the script has finished.

To test this issue, I created the following minimalistic script:

[CODE]
$word = new COM("word.application") or die("Unable to instantiate Word");
$word->Quit();
try {
// If not caugt, a fatal exception is thrown because "Release()" is not defined
// Means, I could also skip this line ...
$word->Release();
} catch (Exception $ex){

}
$word = null;
unset($word);
?>
[/CODE]

The word instance is created fine, the script ends without errors, but the WINWORD.EXE remains in the task manager for eternity ...

Any ideas how to fix this?

My setup:
* Windows 2003 Server
* PHP 5.2.5.5
* Word 2003

Thanks in advance!

Regards, Sascha
--
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Word instance not closing after call to $word->Quit()

am 11.12.2008 16:46:53 von bedul

just my luck.. I have same problem
i wish to build like yours.. but eventualy.. i found a better one..
*still not a better i want

i create the file using HTML and then i put header as word ^^

Sascha Meyer wrote:
> Good morning to you,
>
> one of my scripts creates a winword COM reference, creates a new document, appends data and saves the file to disk; works like a charm, but the word instance remains after the script has finished.
>
> To test this issue, I created the following minimalistic script:
>
> [CODE]
> > $word = new COM("word.application") or die("Unable to instantiate Word");
> $word->Quit();
> try {
> // If not caugt, a fatal exception is thrown because "Release()" is not defined
> // Means, I could also skip this line ...
> $word->Release();
> } catch (Exception $ex){
>
> }
> $word = null;
> unset($word);
> ?>
> [/CODE]
>
> The word instance is created fine, the script ends without errors, but the WINWORD.EXE remains in the task manager for eternity ...
>
> Any ideas how to fix this?
>
> My setup:
> * Windows 2003 Server
> * PHP 5.2.5.5
> * Word 2003
>
> Thanks in advance!
>
> Regards, Sascha
>


--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Word instance not closing after call to $word->Quit()

am 16.12.2008 15:51:57 von Andi Gutmans

Has anyone helped you so far?=20
Looks like a reference counting problem in PHP. There were such problems =
in the past but they were resolved.
I assume this happens with any COM object you are trying to open?

Andi

> -----Original Message-----
> From: Sascha Meyer [mailto:harlequin2@gmx.de]
> Sent: Thursday, December 11, 2008 1:48 AM
> To: php-windows@lists.php.net
> Subject: [PHP-WIN] Word instance not closing after call to =
$word->Quit()
>=20
> Good morning to you,
>=20
> one of my scripts creates a winword COM reference, creates a new =
document,
> appends data and saves the file to disk; works like a charm, but the =
word
> instance remains after the script has finished.
>=20
> To test this issue, I created the following minimalistic script:
>=20
> [CODE]
> > $word =3D new COM("word.application") or die("Unable to instantiate =
Word");
> $word->Quit();
> try {
> // If not caugt, a fatal exception is thrown because =
"Release()" is
> not defined
> // Means, I could also skip this line ...
> $word->Release();
> } catch (Exception $ex){
>=20
> }
> $word =3D null;
> unset($word);
> ?>
> [/CODE]
>=20
> The word instance is created fine, the script ends without errors, but =
the
> WINWORD.EXE remains in the task manager for eternity ...
>=20
> Any ideas how to fix this?
>=20
> My setup:
> * Windows 2003 Server
> * PHP 5.2.5.5
> * Word 2003
>=20
> Thanks in advance!
>=20
> Regards, Sascha
> --
> Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit =
allen:
> http://www.gmx.net/de/go/multimessenger
>=20
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: RE: Word instance not closing after call to$word->Quit()

am 16.12.2008 17:14:32 von harlequin2

Hi Andi,

Andi wrote:
> Has anyone helped you so far?
> Looks like a reference counting problem in PHP. There were such problems
> in the past but they were resolved.
> I assume this happens with any COM object you are trying to open?

I haven't found a solution yet and currently use a workaround (create an html document and send a faked content-type header before sending the content).
I will have to find a way using WORD with COM because the business requires documents with watermarks, page counters, etc and that's just not possible with my current "solution".

To get back to your question: I tried a simple Internet Explorer COM call ...
[CODE]
$iExplore = new COM("InternetExplorer.Application");
sleep(10);
?>
[/CODE]
.... and an instance of Internet Explorer (iexplore.exe) appears in the task list and is automatically disposed when the script ends - I don't even have to call $iExplore->Quit();
Seems as if it is not a general PHP issue but has to do with Word? Do you have any hints for Office-Automation via COM or did you do some tests with different Office and PHP versions? If other versions are more stable, then I would probably have another version installed on the server instead Office 2003.

I will set up a small VBScript to call WINWORD and see if the instance will remain in the task list, perhaps this helps clarify the issue.

Thanks for helping!

Sascha

--
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: RE: Word instance not closing after call to $word->Quit()

am 16.12.2008 17:35:12 von Andi Gutmans

Hi Sascha,

Sometimes it's add-ins which cause such issues such as desktop search =
and others. I suggest to try and disable all add-ins and then try again.
Also you may want to try and start Word in safe mode although I am not =
sure how to do it via COM automation. There may be some option which you =
could pass in.

Let me know if that changes anything.
Andi

> -----Original Message-----
> From: Sascha Meyer [mailto:harlequin2@gmx.de]
> Sent: Tuesday, December 16, 2008 8:15 AM
> To: Andi Gutmans
> Cc: php-windows@lists.php.net
> Subject: Re: RE: [PHP-WIN] Word instance not closing after call to =
$word-
> >Quit()
>=20
> Hi Andi,
>=20
> Andi wrote:
> > Has anyone helped you so far?
> > Looks like a reference counting problem in PHP. There were such =
problems
> > in the past but they were resolved.
> > I assume this happens with any COM object you are trying to open?
>=20
> I haven't found a solution yet and currently use a workaround (create =
an html
> document and send a faked content-type header before sending the =
content).
> I will have to find a way using WORD with COM because the business =
requires
> documents with watermarks, page counters, etc and that's just not =
possible
> with my current "solution".
>=20
> To get back to your question: I tried a simple Internet Explorer COM =
call ...
> [CODE]
> > $iExplore =3D new COM("InternetExplorer.Application");
> sleep(10);
> ?>
> [/CODE]
> ... and an instance of Internet Explorer (iexplore.exe) appears in the =
task
> list and is automatically disposed when the script ends - I don't even =
have to
> call $iExplore->Quit();
> Seems as if it is not a general PHP issue but has to do with Word? Do =
you have
> any hints for Office-Automation via COM or did you do some tests with
> different Office and PHP versions? If other versions are more stable, =
then I
> would probably have another version installed on the server instead =
Office
> 2003.
>=20
> I will set up a small VBScript to call WINWORD and see if the instance =
will
> remain in the task list, perhaps this helps clarify the issue.
>=20
> Thanks for helping!
>=20
> Sascha
>=20
> --
> Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit =
allen:
> http://www.gmx.net/de/go/multimessenger

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Word instance not closing after call to $word->Quit()

am 16.12.2008 17:51:06 von harlequin2

I tried the following VBScript ...

[CODE]
dim objWord

set objWord = CreateObject("Word.Application")
objWord.Visible = true
msgbox objWord.Version
objWord.Quit()
[/CODE]

.... and the result is: Word loads, the version info is displayed and the instance is unloaded again. My only guess is that in this case the calling process is also terminated and all references are released and in case of PHP the process remains because it runs as a child process of IIS?

Once again my system summary for troubleshooting purposes:
Win 2003 SP2
IIS 7
PHP 5.2.6, CGI

Regards, Sascha
--
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Word instance not closing after call to $word->Quit()

am 16.12.2008 23:54:06 von Gang Chen

SGVsbG8gU2FzY2hhLAoKVHJ5IHRvIHJlaW5zdGFsbCBPZmZpY2UuIEkgaGF2 ZSBlbmNvdW50ZXJl
ZCB0aGlzIHByb2JsZW0gYmVmb3JlIGFuZAp0aGUgcmVpbnN0YWxsYXRpb24g c29sdmVzIGl0LiBX
aHkgPyBJIGRvbid0IGtub3cgOi0pCgpSZWdhcmRzLApHYW5nIENoZW4KCjIw MDgvMTIvMTcgU2Fz
Y2hhIE1leWVyIDxoYXJsZXF1aW4yQGdteC5kZT46Cj4gSSB0cmllZCB0aG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