window.setTimeout equivalent in PHP?

window.setTimeout equivalent in PHP?

am 03.09.2007 00:51:14 von Csaba Gabor

Is there a straightforward way of implementing a PHP equivalent to
window.setTimeout?

In a javascript web app, it's often the case that things are done on
an event driven basis. For example, html elements might have things
like onclick="buttonClicked()" to indicate that the function
buttonClicked should be run when that element is clicked.

The analogue can be done in PHP (on Windows) using com_event_sink. In
other words, you can respond to events that a COM object (such as
Excel, Internet Explorer, Words, etc) experiences via a PHP function.
Of course, at the end of your PHP script you would have a loop to the
effect of
while ($GLOBALS['keepLooping']) { com_message_pump(200); }
so that the PHP script stays in memory and doesn't terminate. That is
to say, in this way those event callback functions will be available.
So far, so good.

However, getting a PHP function to run on a timed basis (without any
delay loops) does not seem so easy, which leads to my question: Is
there a straightforward way of implementing a PHP equivalent to
window.setTimeout?

In other words, I'd like to be able to kick off a PHP function after a
certain amount of time has elapsed. One possible way to think of this
is an event driven Sleep. One way to do this is to ensure that I have
a copy of IE up, and then I can use IE's window's own .setTimeout to
tie it into PHP, but this is a bit messy not to mention that I don't
like the IE requirement.

Thanks for any ideas,
Csaba Gabor from Vienna

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 03:09:40 von Jerry Stuckle

Csaba Gabor wrote:
> Is there a straightforward way of implementing a PHP equivalent to
> window.setTimeout?
>
> In a javascript web app, it's often the case that things are done on
> an event driven basis. For example, html elements might have things
> like onclick="buttonClicked()" to indicate that the function
> buttonClicked should be run when that element is clicked.
>
> The analogue can be done in PHP (on Windows) using com_event_sink. In
> other words, you can respond to events that a COM object (such as
> Excel, Internet Explorer, Words, etc) experiences via a PHP function.
> Of course, at the end of your PHP script you would have a loop to the
> effect of
> while ($GLOBALS['keepLooping']) { com_message_pump(200); }
> so that the PHP script stays in memory and doesn't terminate. That is
> to say, in this way those event callback functions will be available.
> So far, so good.
>
> However, getting a PHP function to run on a timed basis (without any
> delay loops) does not seem so easy, which leads to my question: Is
> there a straightforward way of implementing a PHP equivalent to
> window.setTimeout?
>
> In other words, I'd like to be able to kick off a PHP function after a
> certain amount of time has elapsed. One possible way to think of this
> is an event driven Sleep. One way to do this is to ensure that I have
> a copy of IE up, and then I can use IE's window's own .setTimeout to
> tie it into PHP, but this is a bit messy not to mention that I don't
> like the IE requirement.
>
> Thanks for any ideas,
> Csaba Gabor from Vienna
>

No, PHP is not an event-driven language. And, as a web app, it receives
no events from the client.

What exactly are you trying to do?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 04:57:35 von Sandy.Pittendrigh

On Sep 2, 4:51 pm, Csaba Gabor wrote:
> Is there a straightforward way of implementing a PHP equivalent to
> window.setTimeout?
>

You might want to consider programming in java, using the
Google Web Tookit. It's not php. But it is a slick event
driven environment for building complex web-app GUIs.

You program in Java. Communication with the server is done
with a remote method interface that looks a lot like Java RMI.
Your java code is transformed--by the Google compiler--into
javascript, using Ajax or Ajax like messaging to the server.
They do all the browser sniffing for you. The GUIs are
lightning fast. Mouse clicks in dropdown menus
can update a remote database, without refreshing the local
screen. It's overkill for simple websites. But for complex
even driven chatter with a remote database, GWT is hard
to beat.

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 08:30:49 von luiheidsgoeroe

On Mon, 03 Sep 2007 00:51:14 +0200, Csaba Gabor wrote:
> In other words, I'd like to be able to kick off a PHP function after a
> certain amount of time has elapsed. One possible way to think of this
> is an event driven Sleep. One way to do this is to ensure that I have
> a copy of IE up, and then I can use IE's window's own .setTimeout to
> tie it into PHP, but this is a bit messy not to mention that I don't
> like the IE requirement.

Just a side note here: MSIE is not necessary, just a reasonably javascript
capable UA.
--
Rik Wasmus

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 13:32:27 von Csaba Gabor

My question was about CLI PHP (Command Line Interface or CLIent side
php), and not server side processing. The analogy to
window.setTimeout was because many people are familiar with it.

To repeat, the question is: What is the cleanest way of implementing a
PHP equivalent to window.setTimeout (on CLI PHP)?

As mentioned in the original post, it is strightforward to do event
driven programming in php using com_event_sink and com_message_pump.
PHP is happy with client side, event driven processing of COM
objects. Furthermore, a (client side) setTimeout can be implemented
by using IE's own window.setTimeout to call into PHP (presumably,
Excel's Application.OnTime could serve the same purpose), but I was
hoping for a cleaner method.

How am I using this? Consider that I might like to use IE to navigate
a certain sequence of pages. So I have the following, right?:
$ie = new COM("InternetExplorer.Application");
$ie->visible = true; // during development
$ie->Navigate2 ("http://somewhere");

Now normally, one would then have a loop to the tune of
while ($ie->readyState<3) { com_message_pump(200); }
In other words, we wait until ie has loaded the page.

However, I'd like to do this on an event driven basis. That is to
say, when http://somewhere has loaded, I'd like to automatically kick
off a function somewhereHasLoaded($ie). And this is fairly
straightforward by trapping on $ie's downloadComplete event.

However, this isn't the full story, because suppose that something
happens and ie doesn't finish loading. That's why there's always a
timeout for these types of situations. For the loop situation, it's
pretty clear:
while ($ie->readState<3 && time()<$timeoutTime) {
com_message_pump(200); }


However, the event driven situation has a problem. I need to be
signalled both upon the downloadComplete event and also, and upon a
timeout. Hence the question of the cleanest way to do it.


On Sep 3, 12:51 am, Csaba Gabor wrote:
> Is there a straightforward way of implementing a PHP equivalent to
> window.setTimeout?

....

> However, getting a PHP function to run on a timed basis (without any
> delay loops) does not seem so easy, which leads to my question: Is
> there a straightforward way of implementing a PHP equivalent to
> window.setTimeout?
>
> In other words, I'd like to be able to kick off a PHP function after a
> certain amount of time has elapsed. One possible way to think of this
> is an event driven Sleep. One way to do this is to ensure that I have
> a copy of IE up, and then I can use IE's window's own .setTimeout to
> tie it into PHP, but this is a bit messy not to mention that I don't
> like the IE requirement.
>
> Thanks for any ideas,
> Csaba Gabor from Vienna

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 13:38:04 von Norman Peelman

Csaba Gabor wrote:
> Is there a straightforward way of implementing a PHP equivalent to
> window.setTimeout?
>
> In a javascript web app, it's often the case that things are done on
> an event driven basis. For example, html elements might have things
> like onclick="buttonClicked()" to indicate that the function
> buttonClicked should be run when that element is clicked.
>
> The analogue can be done in PHP (on Windows) using com_event_sink. In
> other words, you can respond to events that a COM object (such as
> Excel, Internet Explorer, Words, etc) experiences via a PHP function.
> Of course, at the end of your PHP script you would have a loop to the
> effect of
> while ($GLOBALS['keepLooping']) { com_message_pump(200); }
> so that the PHP script stays in memory and doesn't terminate. That is
> to say, in this way those event callback functions will be available.
> So far, so good.
>
> However, getting a PHP function to run on a timed basis (without any
> delay loops) does not seem so easy, which leads to my question: Is
> there a straightforward way of implementing a PHP equivalent to
> window.setTimeout?
>
> In other words, I'd like to be able to kick off a PHP function after a
> certain amount of time has elapsed. One possible way to think of this
> is an event driven Sleep. One way to do this is to ensure that I have
> a copy of IE up, and then I can use IE's window's own .setTimeout to
> tie it into PHP, but this is a bit messy not to mention that I don't
> like the IE requirement.
>
> Thanks for any ideas,
> Csaba Gabor from Vienna
>

For a web application using PHP and Javascript, using AJAX along with
sessions would work. If you are going to provide a GUI to the users then
PHP-GTK would work (event driven).

Norm

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 14:37:10 von Csaba Gabor

On Sep 3, 1:38 pm, Norman Peelman wrote:
> Csaba Gabor wrote:
> > Is there a straightforward way of implementing a PHP equivalent to
> > window.setTimeout?
....
> > Thanks for any ideas,
> > Csaba Gabor from Vienna
>
> For a web application using PHP and Javascript, using AJAX along with
> sessions would work.

No web app involved. This is strictly client side.

If you are going to provide a GUI to the users then PHP-GTK would work
(event driven).

Would that not require me to insist that all the users of the system
also install a separate component (namely PHP-GTK), in addition to
PHP? Isn't it better to stick stricly within PHP/IE which also
provides a standard event driven GUI, provided I can assume a windows
audience?

> Norm

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 14:42:57 von Jerry Stuckle

Csaba Gabor wrote:
>> However, getting a PHP function to run on a timed basis (without any
>> delay loops) does not seem so easy, which leads to my question: Is
>> there a straightforward way of implementing a PHP equivalent to
>> window.setTimeout?
>>
>> In other words, I'd like to be able to kick off a PHP function after a
>> certain amount of time has elapsed. One possible way to think of this
>> is an event driven Sleep. One way to do this is to ensure that I have
>> a copy of IE up, and then I can use IE's window's own .setTimeout to
>> tie it into PHP, but this is a bit messy not to mention that I don't
>> like the IE requirement.
>>
>> Thanks for any ideas,
>> Csaba Gabor from Vienna
>
> My question was about CLI PHP (Command Line Interface or CLIent side
> php), and not server side processing. The analogy to
> window.setTimeout was because many people are familiar with it.
>
> To repeat, the question is: What is the cleanest way of implementing a
> PHP equivalent to window.setTimeout (on CLI PHP)?
>
> As mentioned in the original post, it is strightforward to do event
> driven programming in php using com_event_sink and com_message_pump.
> PHP is happy with client side, event driven processing of COM
> objects. Furthermore, a (client side) setTimeout can be implemented
> by using IE's own window.setTimeout to call into PHP (presumably,
> Excel's Application.OnTime could serve the same purpose), but I was
> hoping for a cleaner method.
>
> How am I using this? Consider that I might like to use IE to navigate
> a certain sequence of pages. So I have the following, right?:
> $ie = new COM("InternetExplorer.Application");
> $ie->visible = true; // during development
> $ie->Navigate2 ("http://somewhere");
>
> Now normally, one would then have a loop to the tune of
> while ($ie->readyState<3) { com_message_pump(200); }
> In other words, we wait until ie has loaded the page.
>
> However, I'd like to do this on an event driven basis. That is to
> say, when http://somewhere has loaded, I'd like to automatically kick
> off a function somewhereHasLoaded($ie). And this is fairly
> straightforward by trapping on $ie's downloadComplete event.
>
> However, this isn't the full story, because suppose that something
> happens and ie doesn't finish loading. That's why there's always a
> timeout for these types of situations. For the loop situation, it's
> pretty clear:
> while ($ie->readState<3 && time()<$timeoutTime) {
> com_message_pump(200); }
>
>
> However, the event driven situation has a problem. I need to be
> signalled both upon the downloadComplete event and also, and upon a
> timeout. Hence the question of the cleanest way to do it.
>
>
> On Sep 3, 12:51 am, Csaba Gabor wrote:
>> Is there a straightforward way of implementing a PHP equivalent to
>> window.setTimeout?
>
> ...
>

(Top posting fixed)

OK, you're using the wrong tool for this. PHP is server side, not
client side, and has no idea what happens at the client. For instance,
it doesn't know when the client has completed loading the page. All it
knows is that the page has finished executing on the server and passed
the output onto the web server.

You might look into javascript, for instance, which runs on the client.
It can handle the page loaded. But it can't handle a timeout if the
page doesn't get loaded. No one can, AFIAK.

But what are you trying to accomplish with all of this?

P.S. Please don't top post. Thanks.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 15:00:18 von Michael Fesser

..oO(Jerry Stuckle)

>OK, you're using the wrong tool for this. PHP is server side, not
>client side, and has no idea what happens at the client.

Csaba wrote:

| My question was about CLI PHP (Command Line Interface or CLIent side
| php), and not server side processing.

Micha

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 15:14:56 von shimmyshack

On Sep 3, 2:00 pm, Michael Fesser wrote:
> .oO(Jerry Stuckle)
>
> >OK, you're using the wrong tool for this. PHP is server side, not
> >client side, and has no idea what happens at the client.
> Csaba wrote:
>
> | My question was about CLI PHP (Command Line Interface or CLIent side
> | php), and not server side processing.
>
> Micha

Cant you just fire the navigate() method, then sleep for $timeoutTime
and then execute onDocumentComplete or similar, assume that if it
doesn't return true that you are safe to fire an error. However you
recognise that even IE cant tell you whether all the frames in a page
have loaded, and what does onDocumentComplete mean for some remote but
unessential elements - adverts say.. I'm not at all sure that you
should be writing this part in PHP, rather and perhaps more stably
use .NET and expose a COM interface for php to call bespoke methods...

http://msdn2.microsoft.com/en-us/library/aa768329.aspx

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 16:01:04 von Jerry Stuckle

Michael Fesser wrote:
> .oO(Jerry Stuckle)
>
>> OK, you're using the wrong tool for this. PHP is server side, not
>> client side, and has no idea what happens at the client.
>
> Csaba wrote:
>
> | My question was about CLI PHP (Command Line Interface or CLIent side
> | php), and not server side processing.
>
> Micha

Yes, I can read, Micha. My comment stands.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 16:03:43 von Jerry Stuckle

Csaba Gabor wrote:
> On Sep 3, 1:38 pm, Norman Peelman wrote:
>> Csaba Gabor wrote:
>>> Is there a straightforward way of implementing a PHP equivalent to
>>> window.setTimeout?
> ...
>>> Thanks for any ideas,
>>> Csaba Gabor from Vienna
>> For a web application using PHP and Javascript, using AJAX along with
>> sessions would work.
>
> No web app involved. This is strictly client side.
>
> If you are going to provide a GUI to the users then PHP-GTK would work
> (event driven).
>
> Would that not require me to insist that all the users of the system
> also install a separate component (namely PHP-GTK), in addition to
> PHP? Isn't it better to stick stricly within PHP/IE which also
> provides a standard event driven GUI, provided I can assume a windows
> audience?
>
>> Norm
>

Norm,

I wouldn't install PHP on a client just because a web site required it.
I'd go somewhere else, instead.

PHP is not made for client side programming. It does not have any of
the security features, etc.

If I understand what you want to do, you should be looking at java
applets or similar technology. PHP is not the right way to go.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 16:19:47 von Michael Fesser

..oO(Jerry Stuckle)

>Michael Fesser wrote:
>> .oO(Jerry Stuckle)
>>
>>> OK, you're using the wrong tool for this. PHP is server side, not
>>> client side, and has no idea what happens at the client.
>>
>> Csaba wrote:
>>
>> | My question was about CLI PHP (Command Line Interface or CLIent side
>> | php), and not server side processing.
>>
>Yes, I can read, Micha. My comment stands.

The CLI doesn't involve any server. I even use it for shell scripts. Of
course you can write applications in PHP that don't communicate via HTTP
with some other. As far as I understand the OP is using PHP for writing
some kind of Windows application and wants to capture messages sent by
another app.

Micha

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 16:52:12 von Aaron Saray

On Sep 3, 9:19 am, Michael Fesser wrote:
> .oO(Jerry Stuckle)
>
> >Michael Fesser wrote:
> >> .oO(Jerry Stuckle)
>
> >>> OK, you're using the wrong tool for this. PHP is server side, not
> >>> client side, and has no idea what happens at the client.
>
> >> Csaba wrote:
>
> >> | My question was about CLI PHP (Command Line Interface or CLIent side
> >> | php), and not server side processing.
>
> >Yes, I can read, Micha. My comment stands.
>
> The CLI doesn't involve any server. I even use it for shell scripts. Of
> course you can write applications in PHP that don't communicate via HTTP
> with some other. As far as I understand the OP is using PHP for writing
> some kind of Windows application and wants to capture messages sent by
> another app.
>
> Micha

I would suggest starting a while loop with a sleep timeout that checks
something

$myEventHappened = false;
$timeout = 1;

while (true) {
sleep($timeout); // or whatever

/** code to update $myEventHappened **/


if ($myEventHappened) {
/** possibly do something **/

/** maybe change our loop? **/
$timeout = 2;

/** or maybe lets say we exit **/
$myEventHappened = true
}

/** check to see if we should continue **/
if ($myEventHappened) {
break;
}

}


This "might" make sense for you if you're making a client side
("compiled"?) php application for your users.
Of course, I'd take the advice of some people above if you're
programming more client side stuff :)

-aaron

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 16:55:02 von Csaba Gabor

On Sep 3, 3:14 pm, shimmyshack wrote:
> On Sep 3, 2:00 pm, Michael Fesser wrote:
>
> > .oO(Jerry Stuckle)
>
> > >OK, you're using the wrong tool for this. PHP is server side, not
> > >client side, and has no idea what happens at the client.
> > Csaba wrote:
>
> > | My question was about CLI PHP (Command Line Interface or CLIent side
> > | php), and not server side processing.
>
> > Micha
>
> Cant you just fire the navigate() method, then sleep for $timeoutTime
> and then execute onDocumentComplete or similar, assume that if it
> doesn't return true that you are safe to fire an error.

Thanks, this is a great suggestion.

> However you
> recognise that even IE cant tell you whether all the frames in a page
> have loaded, and what does onDocumentComplete mean for some remote but
> unessential elements - adverts say..

This is a good point, but I believe I am aware of the relevant issues
(including the difficulty of associating frames with their
containers). Actually, downloadComplete is the event that I key on.
For example, hit that back button on IE and documentComplete does not
fire, whereas downloadComplete does. However, downloadComplete is
exceptionally poorly designed since all you get back is the IE object,
and not even a handle to the window in question. Nevertheless, for a
situation where I only need access to the top level DOM,
downloadComplete (with $ie->readyState >= 3) suffices.

> I'm not at all sure that you
> should be writing this part in PHP, rather and perhaps more stably
> use .NET and expose a COM interface for php to call bespoke methods...
>
> http://msdn2.microsoft.com/en-us/library/aa768329.aspx

My objections against .NET are
(1) Bloat - the thing is huge, last time I looked, not to mention that
my Win XP configuration needed to change simply as a result of
installing it.
(2) Stability - When I go to Microsoft's web site to download it (OK,
I haven't checked in well over a year) and see zillions of versions,
that is major red flag territory telling me that it's still
effectively a beta product. When I see an unambiguous -> use this
version <- I'll know there's some semblance of stability. Perhaps
it's already happened?
(3) Difficulty of use - I've occasionally seen newsgroup rambling of
how something that is simple with .COM is tortuous with .NET (sorry,
this is just hearsay since I can't recall any specifics, and it is
also old news)
(4) No compelling reason - Nobody has been able to explain to me what
advantage it would offer to me (I.e. what can I not do with COM that I
would want to do with .NET)

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 16:58:44 von Norman Peelman

Jerry Stuckle wrote:
> Csaba Gabor wrote:
>> On Sep 3, 1:38 pm, Norman Peelman wrote:
>>> Csaba Gabor wrote:
>>>> Is there a straightforward way of implementing a PHP equivalent to
>>>> window.setTimeout?
>> ...
>>>> Thanks for any ideas,
>>>> Csaba Gabor from Vienna
>>> For a web application using PHP and Javascript, using AJAX along with
>>> sessions would work.
>>
>> No web app involved. This is strictly client side.
>>
>> If you are going to provide a GUI to the users then PHP-GTK would work
>> (event driven).
>>
>> Would that not require me to insist that all the users of the system
>> also install a separate component (namely PHP-GTK), in addition to
>> PHP? Isn't it better to stick stricly within PHP/IE which also
>> provides a standard event driven GUI, provided I can assume a windows
>> audience?
>>
>>> Norm
>>
>
> Norm,
>
> I wouldn't install PHP on a client just because a web site required it.
> I'd go somewhere else, instead.
>
> PHP is not made for client side programming. It does not have any of
> the security features, etc.
>
> If I understand what you want to do, you should be looking at java
> applets or similar technology. PHP is not the right way to go.
>

Yeah, I understand what you're saying Jerry. The OP hasn't provided
enough details until this last post. I see now that the OP wants to
'drive' IE via PHP without a server. And in his original post says he
doesn't like the idea of having to use IE either. As for your first
sentence, it seems that is exactly what he's doing.

Norm

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 17:26:48 von gosha bine

On 03.09.2007 16:55 Csaba Gabor wrote:
x
>
> My objections against .NET are
> (1) Bloat - the thing is huge, last time I looked, not to mention that
> my Win XP configuration needed to change simply as a result of
> installing it.

I'm wondering why you decided to wrote this in php. WSH + jscript or
vbscript seems to be the "platform of choice" for COM-based scripting.



--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 17:50:31 von Csaba Gabor

On Sep 3, 3:14 pm, shimmyshack wrote:
> Cant you just fire the navigate() method, then sleep for $timeoutTime
> and then execute onDocumentComplete or similar, assume that if it
> doesn't return true that you are safe to fire an error.
....

Hmmm, this excellent suggestion bears a little more thought.
Let's suppose I have $ie go from page1 to page2 to page3
What it means is that inside the downloadComplete event handler for
page1 I'm going to do, per your suggestion, something like:

$callback = "callback2";
downloadComplete_handler_hookup_to_callback ($ie, $callback);
$ie->Navigate2 ("http://page2.com");
while (time()<$timeout) { com_message_pump(200); }
call_user_func ($callback);

Under the assumption that the page finishes promptly (the usual
scenario), I'll have the interesting situation that that event handler
will be invoked twice, concurrently. Once because the previous
invokation is still waiting for the timeout, the second because the
new page will have finished.

If this were Navigate2, then I would not be sanguine about the
chances, since Navigate2 is cancelable. I'm guessing that
downloadComplete should be OK. It will be interesting to see how it
works out.

Csaba Gabor from Vienna

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 17:57:06 von shimmyshack

On Sep 3, 3:55 pm, Csaba Gabor wrote:
> On Sep 3, 3:14 pm, shimmyshack wrote:
>
>
>
>
>
> > On Sep 3, 2:00 pm, Michael Fesser wrote:
>
> > > .oO(Jerry Stuckle)
>
> > > >OK, you're using the wrong tool for this. PHP is server side, not
> > > >client side, and has no idea what happens at the client.
> > > Csaba wrote:
>
> > > | My question was about CLI PHP (Command Line Interface or CLIent side
> > > | php), and not server side processing.
>
> > > Micha
>
> > Cant you just fire the navigate() method, then sleep for $timeoutTime
> > and then execute onDocumentComplete or similar, assume that if it
> > doesn't return true that you are safe to fire an error.
>
> Thanks, this is a great suggestion.
>
> > However you
> > recognise that even IE cant tell you whether all the frames in a page
> > have loaded, and what does onDocumentComplete mean for some remote but
> > unessential elements - adverts say..
>
> This is a good point, but I believe I am aware of the relevant issues
> (including the difficulty of associating frames with their
> containers). Actually, downloadComplete is the event that I key on.
> For example, hit that back button on IE and documentComplete does not
> fire, whereas downloadComplete does. However, downloadComplete is
> exceptionally poorly designed since all you get back is the IE object,
> and not even a handle to the window in question. Nevertheless, for a
> situation where I only need access to the top level DOM,
> downloadComplete (with $ie->readyState >= 3) suffices.
>
> > I'm not at all sure that you
> > should be writing this part in PHP, rather and perhaps more stably
> > use .NET and expose a COM interface for php to call bespoke methods...
>
> >http://msdn2.microsoft.com/en-us/library/aa768329.aspx
>
> My objections against .NET are
> (1) Bloat - the thing is huge, last time I looked, not to mention that
> my Win XP configuration needed to change simply as a result of
> installing it.
> (2) Stability - When I go to Microsoft's web site to download it (OK,
> I haven't checked in well over a year) and see zillions of versions,
> that is major red flag territory telling me that it's still
> effectively a beta product. When I see an unambiguous -> use this
> version <- I'll know there's some semblance of stability. Perhaps
> it's already happened?
> (3) Difficulty of use - I've occasionally seen newsgroup rambling of
> how something that is simple with .COM is tortuous with .NET (sorry,
> this is just hearsay since I can't recall any specifics, and it is
> also old news)
> (4) No compelling reason - Nobody has been able to explain to me what
> advantage it would offer to me (I.e. what can I not do with COM that I
> would want to do with .NET)- Hide quoted text -
>
> - Show quoted text -

I see, I have to say some of the .NET stuff feels more native and
there are great sites like codeproject.com to help out.
I once made a php script to navigate ie, so I could "follow" my users
around one of my sites, and see what they did, there was a javascript
in the head that just sent the users actions back to my home server
where a php script listened, and automated IE, I used it for a while
and then got tired of the weird syntax of php+COM.
It's great though using php's activescripting to do useful tasks on
windows, have you checked out windows powershell though, which offers
power (through .NTE and COM) but also ease of use - with alot of
cmdlets (built in functions) and user cmdlets to download and share.
It's the perfect lightweight tool to automate stuff, like AutoIT3 but
in a shell, without needing to have the user install PHP - which alot
of admins are suspicious of - for instance I use powershell at work
where windows abounds, but php activescripting at home, but powershell
does feel nice - although I'm not master at it yet. my $0.02

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 18:13:00 von Csaba Gabor

On Sep 3, 5:26 pm, gosha bine wrote:
> On 03.09.2007 16:55 Csaba Gabor wrote:
....
> > My objections against .NET are
> > (1) Bloat - the thing is huge, last time I looked, not to mention that
> > my Win XP configuration needed to change simply as a result of
> > installing it.
>
> I'm wondering why you decided to wrote this in php. WSH + jscript or
> vbscript seems to be the "platform of choice" for COM-based scripting.

It's true that those are the platforms of choice, and that's not
surprising. They are Microsoft products that specifically tried to
get people to use those technologies, and they had support for it from
pretty much the beginning. Furthermore, they are quite stable
(especially since development on them has stopped). So they've got
native support, stability, and user base going for them. Not
surprising at all. Plus, the vbscript newsgroups are some of the best
on the block.

Nevertheless, I find PHP much friendlier to use. It's got a far
larger assortment of functions for string, array, and regExp
manipulation, and perhaps most importantly, it is MUCH faster. Almost
everything that you can do in COM, you can do with the COM support
that PHP has. To such an extent that I can write native PHP, full
blown GUI apps, with no third party requirements beyond that of having
PHP (but not PHP-GTK) on a standard windows environment.

Re: window.setTimeout equivalent in PHP?

am 03.09.2007 20:05:28 von Jerry Stuckle

Michael Fesser wrote:
> .oO(Jerry Stuckle)
>
>> Michael Fesser wrote:
>>> .oO(Jerry Stuckle)
>>>
>>>> OK, you're using the wrong tool for this. PHP is server side, not
>>>> client side, and has no idea what happens at the client.
>>> Csaba wrote:
>>>
>>> | My question was about CLI PHP (Command Line Interface or CLIent side
>>> | php), and not server side processing.
>>>
>> Yes, I can read, Micha. My comment stands.
>
> The CLI doesn't involve any server. I even use it for shell scripts. Of
> course you can write applications in PHP that don't communicate via HTTP
> with some other. As far as I understand the OP is using PHP for writing
> some kind of Windows application and wants to capture messages sent by
> another app.
>
> Micha

No, it doesn't. But it requires the user to have PHP on the client
machine, and PHP has no security features. This would leave his machine
wide open to anything the PHP script might want to do.

There is no way I would load PHP on my machine because a web site
required it. And no person with any sense would. Additionally, very
few users with no knowledge of PHP are going to load it on their system,
configure it, etc. If they do, they're opening themselves up to all
kinds of problems.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: window.setTimeout equivalent in PHP?

am 04.09.2007 10:15:08 von Toby A Inkster

Csaba Gabor wrote:

> Nevertheless, I find PHP much friendlier to use. It's got a far
> larger assortment of functions for string, array, and regExp
> manipulation, and perhaps most importantly, it is MUCH faster.

Good argument. VB/VBScript string processing is horrible; Javascript's is
better, but that's not saying much.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 75 days, 11:53.]

TrivialEncoder/0.2
http://tobyinkster.co.uk/blog/2007/08/19/trivial-encoder/

Re: window.setTimeout equivalent in PHP?

am 04.09.2007 11:38:04 von ng4rrjanbiah

On Sep 3, 3:51 am, Csaba Gabor wrote:
> Is there a straightforward way of implementing a PHP equivalent to
> window.setTimeout?


I think, the combination of tick and connections functions are what
you need:

1. http://in.php.net/declare
2. http://in.php.net/connection-handling

--

Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

follwoup: PHP, timers, and event handler callbacks

am 04.09.2007 15:51:16 von Csaba Gabor

On Sep 3, 5:57 pm, shimmyshack wrote:
> > > Cant you just fire the navigate() method, then sleep for $timeoutTime
> > > and then execute onDocumentComplete or similar, assume that if it
> > > doesn't return true that you are safe to fire an error.
>
> > Thanks, this is a great suggestion.
>
> > > However you
> > > recognise that even IE cant tell you whether all the frames in a page
> > > have loaded, and what does onDocumentComplete mean for some remote but
> > > unessential elements - adverts say..
>
> > This is a good point, but I believe I am aware of the relevant issues
> > (including the difficulty of associating frames with their
> > containers). Actually, downloadComplete is the event that I key on.
> > For example, hit that back button on IE and documentComplete does not
> > fire, whereas downloadComplete does. However, downloadComplete is
> > exceptionally poorly designed since all you get back is the IE object,
> > and not even a handle to the window in question. Nevertheless, for a
> > situation where I only need access to the top level DOM,
> > downloadComplete (with $ie->readyState >= 3) suffices.
....
> I see, I have to say some of the .NET stuff feels more native and
> there are great sites like codeproject.com to help out.
> I once made a php script to navigate ie, so I could "follow" my users
> around one of my sites, and see what they did, there was a javascript
> in the head that just sent the users actions back to my home server
> where a php script listened, and automated IE, I used it for a while
> and then got tired of the weird syntax of php+COM.

What an awesome user support idea. I may have to do that, too.

OK, here's the followup / conclusions.

Firstly, the example below is for page sequencing of IE using http://php.net/COM
(again this is with CLI PHP. There is no notion of PHP acting as a
server for these purposes). The actions are therefore navigations,
and button/image/link clicks. Thus, I am particularly interested in
ie's event handlers for when a page finishes loading (which
unfortunately seem to be inadequate) sufficiently that I can work with
it. For my purposes, this means that I am NOT interested in IFRAMES,
etc.

Before worrying about timeouts, I hooked things up to ie's
downloadComplete event, as previously mentioned, so that when it
fired, I knew my page had sufficiently loaded to have a DOM and I was
ready to kick off the next callback function, which in turned
navigated to a subsequent page and so on.

It was blazingly fast. Too fast, in fact. What happened is that as I
loaded the first page (say php.net), I would get the downloadComplete
event firing, so I would start navigating to the next page. That
means that I set a new callback function and started the new
navigation function. And then downloadComplete would fire ON THE OLD
PAGE (say a frame or image had to be loaded in). So my new callback
function would get invoked even though ie was still on the previous
page. And furthermore, I have no idea how many of these
downloadComplete events I'll be receiving in general.

None too happy about this, I grumbled and hooked things up to
documentComplete. Now I got farther, but this time a new issue bit
me. Navigation to the subsequent page involves clicking a button.
Trouble is, the button and containing form get installed via an onload
javascript. The reason it's a problem is that the callback which is
doing the clicking (and finding of the button/form) is reached from
the documentComplete handler, and until that handler returns,
the .onload function does not kick off. Oops. This is a problem,
which as far as I can figure, really force me into using
window.setTimeout functionality.

Seeing no help for it, I wrote a PHP function,
function timer ($msdelay, $callbackName) { // optional arguments }
which keeps a hidden copy of $ie around just so that it can tie into
$ie's window.setTimeout()
So, my documentComplete handler's final line is:
timer (0, "callbackName", $this->ie);
And this works just fine.

But I am not so happy about having to wait around for ads to load just
so $ie's ready state can get to 4 so that documentComplete can fire.
No, I'd much rather the faster downloadComplete. So in the case where
I am assured distinct page as a result of the next navigation, I send
along the beginning (prefix) of the expected url along with the
callback function so that when documentComplete fires, it checks
whether the beginning of its resultant href matches the urlPrefix. If
so, it will dispatch to the callback, otherwise it has to wait for
documentComplete. This is working well, in initial tests.

Finally, I returned to the idea the timeout. Since my actions are no
longer directly invoked directly from within event handlers (ie. I get
there from the event handlers via a timer(...)), I can either use your
loop suggestion or directly use another timer. However, every
callback should have an argument to the tune of $timedOut=false and a
static variable to recognize that it has already been entered. That
is to say, for every action with a timeout, there will be a firing
upon both the action conclusion and upon the timeout. Therefore, the
called function must be reentrant and be able to deal with the second
invokation. For the nonce, I am a happy camper.

Csaba Gabor from Vienna
PS. Initial thread at
http://groups.google.com/group/comp.lang.php/browse_frm/thre ad/fd9e5b193a244739/