By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,199 Members | 1,551 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,199 IT Pros & Developers. It's quick & easy.

window.setTimeout equivalent in PHP?

P: n/a
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

Sep 2 '07 #1
Share this Question
Share on Google+
18 Replies


P: n/a
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.
js*******@attglobal.net
==================
Sep 3 '07 #2

P: n/a
On Sep 2, 4:51 pm, Csaba Gabor <dans...@gmail.comwrote:
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.


Sep 3 '07 #3

P: n/a
On Mon, 03 Sep 2007 00:51:14 +0200, Csaba Gabor <da*****@gmail.comwrote:
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
Sep 3 '07 #4

P: n/a
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 <dans...@gmail.comwrote:
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
Sep 3 '07 #5

P: n/a
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
Sep 3 '07 #6

P: n/a
On Sep 3, 1:38 pm, Norman Peelman <npeel...@cfl.rr.comwrote:
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
Sep 3 '07 #7

P: n/a
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 <dans...@gmail.comwrote:
>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.
js*******@attglobal.net
==================
Sep 3 '07 #8

P: n/a
..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
Sep 3 '07 #9

P: n/a
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.
js*******@attglobal.net
==================
Sep 3 '07 #10

P: n/a
Csaba Gabor wrote:
On Sep 3, 1:38 pm, Norman Peelman <npeel...@cfl.rr.comwrote:
>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.
js*******@attglobal.net
==================
Sep 3 '07 #11

P: n/a
..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
Sep 3 '07 #12

P: n/a
On Sep 3, 9:19 am, Michael Fesser <neti...@gmx.dewrote:
.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

Sep 3 '07 #13

P: n/a
Jerry Stuckle wrote:
Csaba Gabor wrote:
>On Sep 3, 1:38 pm, Norman Peelman <npeel...@cfl.rr.comwrote:
>>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
Sep 3 '07 #14

P: n/a
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
Sep 3 '07 #15

P: n/a
On Sep 3, 5:26 pm, gosha bine <stereof...@gmail.comwrote:
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.

Sep 3 '07 #16

P: n/a
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.
js*******@attglobal.net
==================
Sep 3 '07 #17

P: n/a
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/0...ivial-encoder/
Sep 4 '07 #18

P: n/a
On Sep 3, 3:51 am, Csaba Gabor <dans...@gmail.comwrote:
Is there a straightforward way of implementing a PHP equivalent to
window.setTimeout?
<snip>

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

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Sep 4 '07 #19

This discussion thread is closed

Replies have been disabled for this discussion.