Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

PHP and COM

 
   Database Help (Home) -> PHP RSS
Next:  How to get filesize when stat() fails  
Author Message
X

External


Since: Oct 06, 2008
Posts: 2



(Msg. 1) Posted: Mon Oct 06, 2008 8:01 am
Post subject: PHP and COM
Archived from groups: comp>lang>php (more info?)

When I run this code in PHP, it works for the first time, but when I
try reloading it again, Apache complains of access violation errors.
Got any ideas?

<?php
// starting word
$word = new COM("word.application") or die("Unable to instantiate
Word");
echo "Loaded Word, version {$word->Version}\n";

//bring it to front
$word->Visible = 1;

//open an empty document
$word->Documents->Add();

//closing word
$word->Quit();

//free the object
$word = null;
?>

 >> Stay informed about: PHP and COM 
Back to top
Login to vote
purcaholic

External


Since: May 13, 2007
Posts: 16



(Msg. 2) Posted: Mon Oct 06, 2008 12:31 pm
Post subject: Re: PHP and COM [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 6 Okt., 17:01, X <xet... DeleteThis @gmail.com> wrote:
> When I run this code in PHP, it works for the first time, but when I
> try reloading it again, Apache complains of access violation errors.
> Got any ideas?
>
> <?php
> // starting word
> $word = new COM("word.application") or die("Unable to instantiate
> Word");
> echo "Loaded Word, version {$word->Version}\n";
>
> //bring it to front
> $word->Visible = 1;
>
> //open an empty document
> $word->Documents->Add();
>
> //closing word
> $word->Quit();
>
> //free the object
> $word = null;
> ?>

The code should work, i suppose this is a bug or a missconfiguration
somewhere (Apache, PHP, OS)...

Regards,
purcaholic

 >> Stay informed about: PHP and COM 
Back to top
Login to vote
Richard

External


Since: Jan 15, 2008
Posts: 41



(Msg. 3) Posted: Mon Oct 06, 2008 3:25 pm
Post subject: Re: PHP and COM [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"X" <xethyr RemoveThis @gmail.com> wrote in message
news:39e69842-62b6-41ef-b64f-fea18e366f8c@26g2000hsk.googlegroups.com...
> When I run this code in PHP, it works for the first time, but when I
> try reloading it again, Apache complains of access violation errors.
> Got any ideas?
>
> <?php
> // starting word
> $word = new COM("word.application") or die("Unable to instantiate
> Word");
> echo "Loaded Word, version {$word->Version}\n";
>
> //bring it to front
> $word->Visible = 1;
>
> //open an empty document
> $word->Documents->Add();
>
> //closing word
> $word->Quit();
>
> //free the object
> $word = null;
> ?>

Which versions of
PHP
Word
Apache
OS

etc etc?

R.
 >> Stay informed about: PHP and COM 
Back to top
Login to vote
Jim Carlock

External


Since: Oct 06, 2008
Posts: 4



(Msg. 4) Posted: Mon Oct 06, 2008 4:00 pm
Post subject: Re: PHP and COM [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"X" wrote...
> When I run this code in PHP, it works for the first time, but when I
> try reloading it again, Apache complains of access violation errors.
> Got any ideas?
>
> <?php
> // starting word
> $word = new COM("word.application") or die("Unable to instantiate
> Word");
> echo "Loaded Word, version {$word->Version}\n";
>
> //bring it to front
> $word->Visible = 1;
>
> //open an empty document
> $word->Documents->Add();
>
> //closing word
> $word->Quit();
>
> //free the object
> $word = null;
> ?>

Try...

//open an empty document
$word->Documents->Add();
$word->Documents->Close();

I imagine it's possible that you're not closing the document
you opened when you try to shut down Word. You might need to
throw an index as the Documents[] may be an array.

I would use more appropriate variable names as well. Something
along the lines of...

$oMS_Word = new COM("word.application");
// check for $oMS_Word object or check for error.

When you create a new document, word usually asks if you'd like
to save the document. So you might want check for return values
when closing the document.

I'm interested in this topic for other reasons. I do not want to
open Word documents, I want to connect to a .dll and create an
object from a specific DLL file.

--
Jim Carlock
You Have More Than Five Senses
http://www.associatedcontent.com/article/381163/more_than_five_senses.html
 >> Stay informed about: PHP and COM 
Back to top
Login to vote
Oscar Arreyano

External


Since: Oct 02, 2008
Posts: 8



(Msg. 5) Posted: Tue Oct 07, 2008 10:32 am
Post subject: Re: PHP and COM [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"X" <xethyr.TakeThisOut@gmail.com> wrote in message
news:39e69842-62b6-41ef-b64f-fea18e366f8c@26g2000hsk.googlegroups.com...
> When I run this code in PHP, it works for the first time, but when I
> try reloading it again, Apache complains of access violation errors.
> Got any ideas?
>
> <?php
> // starting word
> $word = new COM("word.application") or die("Unable to instantiate
> Word");
> echo "Loaded Word, version {$word->Version}\n";
>
> //bring it to front
> $word->Visible = 1;
>
> //open an empty document
> $word->Documents->Add();
>
> //closing word
> $word->Quit();
>
> //free the object
> $word = null;
> ?>

RTFM !!!

Had you, you'd have seen the FIRST COM example was one for Word...and that
in *every* example, the last thing you should always do is
$com->Release...as in, $word->Release();

The error is not with your OS, or PHP, or Apache. You have created a
potential memory leak. What's funny is that Windows, architectually, has
caught your oversight and is returning the error. So, next time you want to
bitch about MS, please remember you're still not up to even their level of
expertise. :^)

Cheers
 >> Stay informed about: PHP and COM 
Back to top
Login to vote
Álvaro_G._Vicario

External


Since: Apr 11, 2008
Posts: 980



(Msg. 6) Posted: Tue Oct 07, 2008 1:25 pm
Post subject: Re: PHP and COM [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Oscar Arreyano escribió:
> RTFM !!!
>
> Had you, you'd have seen the FIRST COM example was one for Word...and that
> in *every* example, the last thing you should always do is
> $com->Release...as in, $word->Release();
>
> The error is not with your OS, or PHP, or Apache. You have created a
> potential memory leak. What's funny is that Windows, architectually, has
> caught your oversight and is returning the error. So, next time you want to
> bitch about MS, please remember you're still not up to even their level of
> expertise. :^)

Two quick remarks:

1. The OP's sample code is a copy & paste from the PHP manual.
2. The Release() method has a "You should never need to use this method"
red warning.

I don't know whether it's a documentation issue but...

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
 >> Stay informed about: PHP and COM 
Back to top
Login to vote
Oscar Arreyano

External


Since: Oct 02, 2008
Posts: 8



(Msg. 7) Posted: Tue Oct 07, 2008 1:29 pm
Post subject: Re: PHP and COM [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

""Álvaro G. Vicario"" <alvaroNOSPAMTHANKS.DeleteThis@demogracia.com> wrote in message
news:gcg2vd$3l0$1@huron.algomas.org...
> Oscar Arreyano escribió:
>> RTFM !!!
>>
>> Had you, you'd have seen the FIRST COM example was one for Word...and
>> that in *every* example, the last thing you should always do is
>> $com->Release...as in, $word->Release();
>>
>> The error is not with your OS, or PHP, or Apache. You have created a
>> potential memory leak. What's funny is that Windows, architectually, has
>> caught your oversight and is returning the error. So, next time you want
>> to bitch about MS, please remember you're still not up to even their
>> level of expertise. :^)
>
> Two quick remarks:
>
> 1. The OP's sample code is a copy & paste from the PHP manual.
> 2. The Release() method has a "You should never need to use this method"
> red warning.
>
> I don't know whether it's a documentation issue but...

Probably so. Unless php does COM garbage collecting automatically, Word will
stay resident in memory until the apache/php process is restarted...unless
you explicity call 'release'.
 >> Stay informed about: PHP and COM 
Back to top
Login to vote
Richard

External


Since: Jan 15, 2008
Posts: 41



(Msg. 8) Posted: Tue Oct 07, 2008 4:25 pm
Post subject: Re: PHP and COM [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Oscar Arreyano" <another.DeleteThis@example.com> wrote in message
news:giLGk.2936$YU2.99@nlpi066.nbdc.sbc.com...
> "X" <xethyr.DeleteThis@gmail.com> wrote in message
> news:39e69842-62b6-41ef-b64f-fea18e366f8c@26g2000hsk.googlegroups.com...
>> When I run this code in PHP, it works for the first time, but when
>> I
>> try reloading it again, Apache complains of access violation
>> errors.
>> Got any ideas?
>>
>> <?php
>> // starting word
>> $word = new COM("word.application") or die("Unable to instantiate
>> Word");
>> echo "Loaded Word, version {$word->Version}\n";
>>
>> //bring it to front
>> $word->Visible = 1;
>>
>> //open an empty document
>> $word->Documents->Add();
>>
>> //closing word
>> $word->Quit();
>>
>> //free the object
>> $word = null;
>> ?>
>
> RTFM !!!
>
> Had you, you'd have seen the FIRST COM example was one for
> Word...and that in *every* example, the last thing you should always
> do is $com->Release...as in, $word->Release();
>
> The error is not with your OS, or PHP, or Apache. You have created a
> potential memory leak. What's funny is that Windows, architectually,
> has caught your oversight and is returning the error. So, next time
> you want to bitch about MS, please remember you're still not up to
> even their level of expertise. :^)
>
> Cheers
>


Who is bitching here?
He jsut pasted his example, thats all!

Tone it down a bit, k?

R.
 >> Stay informed about: PHP and COM 
Back to top
Login to vote
Oscar Arreyano

External


Since: Oct 02, 2008
Posts: 8



(Msg. 9) Posted: Tue Oct 07, 2008 6:26 pm
Post subject: Re: PHP and COM [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Richard" <root@localhost> wrote in message
news:48ebbadc$0$24266$dbd49001@news.euronet.nl...
>
> "Oscar Arreyano" <another.TakeThisOut@example.com> wrote in message
> news:giLGk.2936$YU2.99@nlpi066.nbdc.sbc.com...
>> "X" <xethyr.TakeThisOut@gmail.com> wrote in message
>> news:39e69842-62b6-41ef-b64f-fea18e366f8c@26g2000hsk.googlegroups.com...
>>> When I run this code in PHP, it works for the first time, but when I
>>> try reloading it again, Apache complains of access violation errors.
>>> Got any ideas?
>>>
>>> <?php
>>> // starting word
>>> $word = new COM("word.application") or die("Unable to instantiate
>>> Word");
>>> echo "Loaded Word, version {$word->Version}\n";
>>>
>>> //bring it to front
>>> $word->Visible = 1;
>>>
>>> //open an empty document
>>> $word->Documents->Add();
>>>
>>> //closing word
>>> $word->Quit();
>>>
>>> //free the object
>>> $word = null;
>>> ?>
>>
>> RTFM !!!
>>
>> Had you, you'd have seen the FIRST COM example was one for Word...and
>> that in *every* example, the last thing you should always do is
>> $com->Release...as in, $word->Release();
>>
>> The error is not with your OS, or PHP, or Apache. You have created a
>> potential memory leak. What's funny is that Windows, architectually, has
>> caught your oversight and is returning the error. So, next time you want
>> to bitch about MS, please remember you're still not up to even their
>> level of expertise. :^)
>>
>> Cheers
>>
>
>
> Who is bitching here?
> He jsut pasted his example, thats all!
>
> Tone it down a bit, k?

No, had he pasted the example, $word->Release() would have been called as
well...in the manual, it's right inbetween $word->Quit() and $word = null

But, I will tone it down...just for you. :^)
 >> Stay informed about: PHP and COM 
Back to top
Login to vote
X

External


Since: Oct 06, 2008
Posts: 2



(Msg. 10) Posted: Wed Oct 08, 2008 9:28 am
Post subject: Re: PHP and COM [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Oct 7, 6:26 pm, "Oscar Arreyano" <anot... DeleteThis @example.com> wrote:
> "Richard" <root@localhost> wrote in message
>
> news:48ebbadc$0$24266$dbd49001@news.euronet.nl...
>
>
>
>
>
> > "Oscar Arreyano" <anot... DeleteThis @example.com> wrote in message
> >news:giLGk.2936$YU2.99@nlpi066.nbdc.sbc.com...
> >> "X" <xet... DeleteThis @gmail.com> wrote in message
> >>news:39e69842-62b6-41ef-b64f-fea18e366f8c@26g2000hsk.googlegroups.com....
> >>> When I run this code in PHP, it works for the first time, but when I
> >>> try reloading it again, Apache complains of access violation errors.
> >>> Got any ideas?
>
> >>> <?php
> >>> // starting word
> >>> $word = new COM("word.application") or die("Unable to instantiate
> >>> Word");
> >>> echo "Loaded Word, version {$word->Version}\n";
>
> >>> //bring it to front
> >>> $word->Visible = 1;
>
> >>> //open an empty document
> >>> $word->Documents->Add();
>
> >>> //closing word
> >>> $word->Quit();
>
> >>> //free the object
> >>> $word = null;
> >>> ?>
>
> >> RTFM !!!
>
> >> Had you, you'd have seen the FIRST COM example was one for Word...and
> >> that in *every* example, the last thing you should always do is
> >> $com->Release...as in, $word->Release();
>
> >> The error is not with your OS, or PHP, or Apache. You have created a
> >> potential memory leak. What's funny is that Windows, architectually, has
> >> caught your oversight and is returning the error. So, next time you want
> >> to bitch about MS, please remember you're still not up to even their
> >> level of expertise. :^)
>
> >> Cheers
>
> > Who is bitching here?
> > He jsut pasted his example, thats all!
>
> > Tone it down a bit, k?
>
> No, had he pasted the example, $word->Release() would have been called as
> well...in the manual, it's right inbetween $word->Quit() and $word = null
>
> But, I will tone it down...just for you. :^)

Umm, hi.

My example is from here: http://us3.php.net/manual/en/class.com.php.
It's from "COM example (1)." This is the original code I copied from:

<?php
// starting word
$word = new COM("word.application") or die("Unable to instantiate
Word");
echo "Loaded Word, version {$word->Version}\n";

//bring it to front
$word->Visible = 1;

//open an empty document
$word->Documents->Add();

//do some weird stuff
$word->Selection->TypeText("This is a test...");
$word->Documents[1]->SaveAs("Useless test.doc");

//closing word
$word->Quit();

//free the object
$word = null;
?>

I removed code to save a Word doc cuz I felt opening up Word and
loading the version number is a sufficient enough test. Either way,
when I run this example, I get the access violation error. The first
code example does not include a call to Release(), and when I add it
in, I get a new error, a com_exception saying that the Release()
member is not found. I DID read the PHP manual, and I can't make a
call to Release() on a COM object, at least not with PHP 5.2.6 (the
version of PHP I'm using). The PHP manual says that this method has
been removed since 5.0 (http://us3.php.net/manual/en/function.com-
release.php).

I am running PHP 5.2.6, Word 2007, and Apache 2.2.9.

I wasn't "bitching about MS." I was trying to run a code example from
the PHP website and was asking for help on how to get it to work. I
pasted the code example and reported the error I received. How is that
bitching?
 >> Stay informed about: PHP and COM 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> PHP All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]