1 person found this helpful
I don't think PHP can do push out of the box, unless you write your own
mechanism, maybe integrate with some already existing messaging. So you probably
better of doing heavy polling. You can do that in flex with Timers. My advice
would be to poll frequently for something like a heartbeat data, very small
amount of status data and based on that you can ask for more. You don't want to
make calls for data which is not that important and waist bandwidth for nothing.
I worked on something like that for games with rounds so based on game progress
we only made calls for certain data and update only that parts. The hearbeat had
the game status, round number, round progress %, etc ...
Hope this makes sense as a high level hint.
Share some details and I can go into more specifics...
This is really helpful, thanks.
In my application I'm calling fetchData() which fetches data from the PHP application through Zend AMF into a Data Grid. I've tried using setInterval(fetchData, 3000) to poll every 3 seconds and it seems to work.
However some articles I saw online said PHP can act as a socket server to send data to the client. Another article also suggested connecting Flex to BlazeDS, and BlazeDS to PHP. Are these solutions I should be considering or is long polling the best choice?
1 person found this helpful
The BlazeDS part is the one where you integrate with an already existing
application. I would not go that far. Flex has the Socket class, you can do the
push through the sockets. As far as I know (din not write that much php lately)
php also implements sockets. That means that you can maintain a socket
(permanent) connection between flex and php (not sure how Zend fits into this
you might find that Zend has it's own wrapper classes over php sockets). Your
php will have to basically send updates to flex then flex updates datagrid
accordingly, only now the data is pushed from php, which will also handle the
timing of the updates e.g where to send them. Not sure about the load on your
than push-ing when it comes to concurrent connections.
In the end there si no best solution just a solution that fits best in your
situation. I would replace the setInterval with a Timer as a better practice. If
you only update a grid with some data I would not go any further just leave it
like that. However you know your application better. Implementing the socket
might require some php development also you need to refactor the flex client ...
Do the math and see what's better for you...
What do you mean when you say that polling scales better compared to push?
If I went for polling, is there anything I could do to the web server to achieve the fastest possible connection, i.e. should I consider persistent connections for Apache? Or would a different web server be better practice, e.g. lighttpd?
If your server takes 100K concurrent connection with push (permanent connection)
it can serve 100K concurrent users/client apps. With polling it can serve more
than 100K since it opens a connection and then closes it after the response has
been sent, so until that client polls again it can handle other requests from
other clients ...
Ah OK I see what you mean.
What about WebOrb ? Does it support realtime push ?
How about performance, JAVA vs. PHP
Anyone ever tried to push audio data trough a socket connection using PHP to a Flex client ?
These days I'm using setInterval() in my application. It works really well too. When whatever I want to poll is visible, the interval is set and the server is polled every X seconds for updates. Server-side it checks if anything's changed and, if so, returns the data. If nothing's changed, nothing's returned.
When the hide event is fired, the polling is paused, and when the show event is fired, it resumes.
I'm using Zend AMF. WebORB was too over-complex and is hardly maintained, whereas Zend AMF is updated monthly.
I am not using PHP, but I dont think it really matters what technology is running on the server. I am pushing up to 30-40 simultaneous data scans from the server to the Flex application.
Works like a tank.
How do you do data push with php to flex without calling the php from flex ??
Any Example please ?
The way it works for me...
Each Flex application that is going to send/receive massages creates a socket connection and either writes into it or listens to. But Flex obviously cannot create a socket on the server, so for that I have another program (C# Console program) that creates sockets and forwards every message a socket receives to all connected clients (Flex applications in this case).