How can I read data from long running php script? I see that there's onProgress event in Request object but data is not included in event or in xhr

197 views
Skip to first unread message

underscore_05

unread,
Apr 11, 2013, 7:28:55 AM4/11/13
to mootool...@googlegroups.com

underscore_05

unread,
Apr 11, 2013, 8:31:09 AM4/11/13
to mootool...@googlegroups.com
What Im  trying to do is to perform a streaming like script.
 
A php script is always pending and will push a data to the browser once detected a changes in the database (And its already done). But the problem is I cant catch the pushed data in onSuccess event or in onComplete event of Request object.
 
I found resources in the web but it is using Node.JS and Socket.IO and I dont want yet to go in that direction.

Sanford Whiteman

unread,
Apr 11, 2013, 3:53:37 PM4/11/13
to underscore_05
> A php script is always pending and will push a data to the browser
> once detected a changes in the database (And its already done). But
> the problem is I cant catch the pushed data in onSuccess event or in
> onComplete event of Request object.

This pattern is called "Ajax long polling." It's quite serviceable for
apps that need to be flat cross-modern-browser (without progressive
enhancement) and when you're not using an actual evented back-end
(i.e. you are using PHP). (Some would say it's dangerously
unscaleable, but let's ignore that caution for now.)

In other words, this should work just fine. Nothing fancy but also
nothing that Moo isn't built to handle. The connection runs for a long
time, it finally gets something, it calls onSuccess. To the client
with a reliable connection, it's no different from a short Ajax call
and uses fewer resources on the client than if you had the client loop
constantly.

You say the PHP script is working fine. What happens if you return
dummy data immediately without polling/waiting for any changes in the
database? Then work with PHP's sleep() command to add a delay with no
other complications. Only then plug in your actual db code. Is PHP
timing out (see set_time_limit(0)) when you use the real db code? This
is how you'd troubleshoot such things.

-- S.


Richard Neil Roque

unread,
Apr 11, 2013, 8:30:12 PM4/11/13
to mootool...@googlegroups.com
I already made a PHP script that returns a data and terminates after it returns that data. After mootools receive that data, I made a followup request. But, what I now trying to do is a very long running php script which returns data but dont terminate immediately. It can return 10 data in different time(more like a delayed loading of data, but data loaded is based on the changes in the database). But that data cant be catched by Request handler. 
BTW. Thank you, if that approach wont work I think I will stick with immediately terminating the PHP script and request another after Mootools processed that data. 

Sanford Whiteman

unread,
Apr 11, 2013, 9:43:17 PM4/11/13
to Richard Neil Roque
> It can return 10 data in different time(more like a delayed loading
> of data, but data loaded is based on the changes in the database).
> But that data cant be catched by Request handler. 

In this case, you're looking at streaming approaches such as HTMLFile
in IE and Server-Sent Events on other browsers. Rather than reinvent
the wheel, you should use a library such as SockJS for this (MooTools
does not have the full client socket progressive
enhancement/fallback).

-- S.

Richard Neil Roque

unread,
Apr 12, 2013, 2:36:26 AM4/12/13
to mootool...@googlegroups.com
Thank you, I think i will stick to my first approach for now (using wait for data and send another long poll). And will just refactor my server side code and my js.



-- S.

--

---
You received this message because you are subscribed to a topic in the Google Groups "MooTools Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mootools-users/_xMX_L9LuU4/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to mootools-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Reply all
Reply to author
Forward
0 new messages