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

window.setTimeout equivalent in PHP?

 
Goto page Previous  1, 2
   Database Forums (Home) -> PHP RSS
Next:  Error with < in SQL  
Author Message
Aaron Saray

External


Since: Sep 01, 2007
Posts: 5



(Msg. 16) Posted: Mon Sep 03, 2007 12:00 pm
Post subject: Re: window.setTimeout equivalent in PHP? [Login to view extended thread Info.]
Archived from groups: comp>lang>php (more info?)

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 Smile

-aaron

 >> Stay informed about: window.setTimeout equivalent in PHP? 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 1367



(Msg. 17) Posted: Mon Sep 03, 2007 2:05 pm
Post subject: Re: window.setTimeout equivalent in PHP? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.DeleteThis@attglobal.net
==================

 >> Stay informed about: window.setTimeout equivalent in PHP? 
Back to top
Login to vote
Csaba Gabor

External


Since: Sep 02, 2007
Posts: 9



(Msg. 18) Posted: Mon Sep 03, 2007 2:55 pm
Post subject: Re: window.setTimeout equivalent in PHP? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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)
 >> Stay informed about: window.setTimeout equivalent in PHP? 
Back to top
Login to vote
Csaba Gabor

External


Since: Sep 02, 2007
Posts: 9



(Msg. 19) Posted: Mon Sep 03, 2007 3:01 pm
Post subject: Re: window.setTimeout equivalent in PHP? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.
 >> Stay informed about: window.setTimeout equivalent in PHP? 
Back to top
Login to vote
Csaba Gabor

External


Since: Sep 02, 2007
Posts: 9



(Msg. 20) Posted: Mon Sep 03, 2007 3:50 pm
Post subject: Re: window.setTimeout equivalent in PHP? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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
 >> Stay informed about: window.setTimeout equivalent in PHP? 
Back to top
Login to vote
gosha bine

External


Since: Apr 19, 2007
Posts: 27



(Msg. 21) Posted: Mon Sep 03, 2007 5:26 pm
Post subject: Re: window.setTimeout equivalent in PHP? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 Wink http://code.google.com/p/pihipi
 >> Stay informed about: window.setTimeout equivalent in PHP? 
Back to top
Login to vote
R. Rajesh Jeba Anbiah

External


Since: Jun 10, 2007
Posts: 2



(Msg. 22) Posted: Tue Sep 04, 2007 2:38 am
Post subject: Re: window.setTimeout equivalent in PHP? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Sep 3, 3:51 am, Csaba Gabor wrote:
> 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/
 >> Stay informed about: window.setTimeout equivalent in PHP? 
Back to top
Login to vote
Csaba Gabor

External


Since: Sep 02, 2007
Posts: 9



(Msg. 23) Posted: Tue Sep 04, 2007 6:51 am
Post subject: follwoup: PHP, timers, and event handler callbacks [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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/thread/fd9e5b193a244739/
 >> Stay informed about: window.setTimeout equivalent in PHP? 
Back to top
Login to vote
Toby A Inkster

External


Since: Nov 13, 2007
Posts: 29



(Msg. 24) Posted: Tue Sep 04, 2007 9:15 am
Post subject: Re: window.setTimeout equivalent in PHP? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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/
 >> Stay informed about: window.setTimeout equivalent in PHP? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Equivalent of upvar - Is there a PHP equivalent of TCL's "upvar" ? I will appreciate any insights. Andy

PHP equivalent to Perl's !~ - I haven't seen any documentation on this, and searching for !~ has been fruitless. Any suggestions, or is there no equivalent?

Does PHP have an equivalent of JavaScript's prototype obje.. - Basically, I want to add default methods to the PHP string object so that I can do something like: $stringvar = "hello"; $stringvar -> append(" world"); // where append is some kind of prototyped function i define echo $stringva...

Newbie - Is there a PHP equivalent of Server.Transfer (in .. - Hello, Sorry for the newbie question, but I've only been at PHP for a couple of days, and I'm trying to get some stuff done as fast as possible. I'm an experienced ASP.NET programmer, and am trying to find some equivalent stuff in PHP. In ASP.NET..

Size new window - Hi all The following code ( using target='_blank' ) opens a "normal" big size window. <a target='_blank' href='page2.php'>HERE</a> How can I open a window with a small size? TIA John
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Goto page Previous  1, 2
Page 2 of 2

 
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 ]