I have a market prices table, it updated every millisecond from a third-party service.
I need something to display the live prices to my HTML view, I don't want to use ajax
Asynchronous JavaScript probably is the easiest and lowest latency (best) solution although it still won't likely provide you to the millisecond accuracy.
Presenting the raw data source in a html frame that is repeatedly refresh via JavaScript may be an option depending on formatting needs but this has it's own challenges and is a bit of a hack.
You might be able to achieve this with static site generation task (rebuild) scheduling but you would be looking at even larger latency in that case, people would also need to refresh the page to see the updated data unless you refresh the page on an interval with this solution.
When dealing with markup the content will either need to be refreshed by JavaScript or by browser refresh.
To display data live, yes! websockets are the answer. Though you can't run them on the same server your default Laravel server relies. You'll need to create a different server via Artisan console or Task scheduler listening on a different port. Make sure your hosting provider supports the ability to listen over other ports than 80/443. You may need a VPS or something serverless to run such application.
The only reliable websocket PHP library which I know it has good integrity with Laravel is Ratchet.
Though I advise NodeJS with SocketIO when it comes to websocket applications.
Related
I'm working on a React app with data being pulled from my GraphQL API and I want to ensure the loading animations are working as intended. The problem is the requests are so quick in development that I only see a glimpse of the animation. I was wondering if there is any way to intentionally slow down requests to my localhost GraphQL server to simulate a poor connection, slow server etc.
I know that I could just hard code my loading animation to display but I want to simulate the actual use to see if it's all working correctly. This might be a very stupid and unnecessary thing to be asking. If so, just let me know.
For reference, I am using Apollo Client on the frontend and Apollo Express Server on the backend with Node.js.
Yes, you can go into the Network Tab in Chrome and then select No throttling and a dropdown with preset options you will see like Fast 3G, and Slow 3G. You can also add your Custom throttling setup where you can specify how many kbit/s you want to download.
I have to create a little AJAX chat in my web application and I'm dealing with problem of real-time communication between JavaScript client and PHP server.
I want my js client to be able to catch new messages from the server as quick as possible. My first idea was to create AJAX request for example each 5 sec. to see whether there are new messages.
However, I'm not sure what happens if my application use for example 1000 people, it must be huge load to Apache httpd.
I also know about technique called 'long-polling' request, but when I tried that locally on my server, I've completely shooted down my Apache (I've read sth about problems with apache and long-polling). The next way I know about is WebSocket.
However, is it true that I have to be able to open port on webserver to use it? Because on regular web hosting, I thing it's not possible and I cant change any Apache/PHP settings on my hosting.
Do you have any suggestions how to solve it?
If you want to use websockets, you better have full control over your server as you may be facing the need to start and stop the websocket daemon whenever it's needed.
I wouldn't recommend using "regular web hosting" because of its restrictions.
I think that you are looking for "virtual server providers", that provides you full control over the server you manage. You should look at Amazon Web Services. There are many others that you may find.
I'm doing a pet project with Symfony. In it, I scrape and parse the content of a few websites and APIs (it's all for personal use), and mix everything together. Up until now, I've been separating all the different retrieval processes, and basically it works like this: I have a menu, and each button updates something. When I push it, some website is loaded, the content is parsed and my database is updated. This takes some time, depending on the website loading time, the parsing etc. Basically, when I choose to update something, I lose control and I have no output about the situation until everything is done.
I'm rethinking the whole process, and the way I see this is having a page where I push a button, and a "permanent" connection is established with the server. Then, one thing a time, everything is updated. This could take some time (I would guess even 20 minutes), and therefore the server notifies the client with updates, and possibly even requires the user to make choices (I'm connecting data from different sources, and there are a few edge cases where it just can't automatically guess the right relationships).
I'm thinking about the best way to implement this. At first I thought simple Ajax/jQuery would work, but it seems to me that the relationship between client/server is too permanent and bidirectional to be able to keep everything simple. Then I thought about working with streams and/or websockets, but I don't really know the topics.
What is the best/correct way to do this, especially in a Symfony context?
I don't think this is really tight to Symfony, what you are looking for is called Server Sent Events.
Server-sent events (SSE) is a technology for a browser to get
automatic updates from a server via HTTP connection. The Server-Sent
Events EventSource API is standardized as part of HTML5 by the W3C.
For PHP in general, I generally use the Hoa\EventSource library which makes things easy
For Symfony, you can have a dedicated API endpoint that will use this library.
Maybe the title could be rephrased slightly better but basically I'm wondering how the likes of facebook have implemented a 'live' interface with regards to new notifications/messages etc. I know that the complexity behind such a social network is too much to discuss in this one small SO thread but if anyone has any idea as to the technologies used in order to notify it's users almost immediately of new records (I'm assuming DB records) then I'd be curious to hear it.
If I were to guess, I'd say that there were timers on client-side code that would periodically check the database via AJAX and then react accordingly. Is this right?
It is via Comet and long polling via node.js or similar non-thread based web servers.
If I were to guess, I'd say that there were timers on client-side code that would periodically check the database via AJAX and then react accordingly. Is this right?
You are partially right. The client opens a connection and the server only responds once it has something to return to the client.
I think they are trying to use HTML5 WebSockets but as a fallback they using Comet, AJAX, Long pooling with a good backend.
I'm working on the design of a web app which will be using AJAX to communicate with a server on an embedded device. But for one feature, the client will need to get very frequent updates (>10 per second), as close to real time as possible, for an extended period of time. Meanwhile typical AJAX requests will need to be handled from time to time.
Some considerations unique to this project:
This data will be very small, probably no more than a single numeric value.
There will only be 1 client connected to the server at a time, so scaling is not an issue.
The client and server will reside on the same local network, so the connection will be fast and reliable.
The app will be designed for Android devices, so we can take advantage of any platform-specific browser features.
The backend will most likely be implemented in Python using WSGI on Apache or lighttpd, but that is still open for discussion.
I'm looking into Comet techniques including XHL long polling and hidden iframe but I'm pretty new to web development and I don't know what kind of performance we can expect. The server shouldn't have any problem preparing the data, it's just a matter of pushing it out to the client as quickly as possible. Is 10 updates per second an unreasonable expectation for any of the Comet techniques, or even regular AJAX polling? Or is there another method you would suggest?
I realize this is ultimately going to take some prototyping, but if someone can give me a ball-park estimate or better yet specific technologies (client and server side) that would provide the best performance in this case, that would be a great help.
You may want to consider WebSockets. That way you wouldn't have to poll, you would receive data directly from your server. I'm not sure what server implementations are available at this point since it's still a pretty new technology, but I found a blog post about a library for WebSockets on Android:
http://anismiles.wordpress.com/2011/02/03/websocket-support-in-android%E2%80%99s-phonegap-apps/
For a Python back end, you might want to look into Twisted. I would also recommend the WebSocket approach, but failing that, and since you seem to be focused on a browser client, I would default to HTTP Streaming rather than polling or long-polls. This jQuery Plugin implements an http streaming Ajax client and claims specifically to support Twisted.
I am not sure if this would be helpful at all but you may want to try Comet style ajax
http://ajaxian.com/archives/comet-a-new-approach-to-ajax-applications