I have a sensor that can send HTTP GET requests containing data. I want to receive this data and send it to a webpage. I want the webpage to update when we get new data. We get new data about every 2 minutes. I want the data to be as up-to-date as possible.
How do i accept the incoming push from the sensor?
How do i take that and update the webpage?
Currently I'm querying the sensor for data, but that is putting too much load on the sensor as every user who has a webpage open is constantly making requests to the sensor. This is the reason I'd like to switch to having the sensor send the data out on set intervals. I've been reading about SSE and web-hooks etc. but need some direction on tying this all together.
Just in your procces
http://localhost?id=1
$_GET['id'];
And
in youur view
<?php echo "$_GET['id']";?>
Related
I am new to the term webhook, and i understand that it is a normal HTTP POST request, so when i send the data to an endpoint it utilizes this data and i can test this on a tool like (webhook.site), and what is noticeable on webhook.site it shows me directly the posted data on the real time. I need some help to know how this real time updates can be done using a custom webhook. If i created a PHP file that with will receive a posted data i don't know how to update the page upon request automatically.
This is what I am thinking:
On the mobile app I have, the user can complete a number of forms. To get this on to a server, I will:
On the mobile app, loop over all of the completed forms. One at a time, use JSON to send that form data to a webservice.
PHP Webservice picks up JSON requests, inserts the data into a database.
Once data is confirmed to be inserted in the database, the PHP script returns a simple JSON response to acknowledge the data has been received.
Mobile app receives this acknowledgement and deletes that local form data. The loop continues to the next form, and the process repeats...
I'm wondering if there are better ways of copying data than the way I outlined above?
I want to receive the post request on a web page while my page isn't refreshing or is still or just open, sort of concept like dynamic messages without refreshing the page. I don't want to pull it using ajax
I tried sending request to that URL but that doesn't work. I wanted to know a way to receive a post data and display it to user.
Any help is appreciated.
I read about amazon sns push for http/s, but they too doesn't send request to each browser page. they just send the request to the server, how should i make things in a way that , that post request from amazon goes to every browser page wherever it is open and display the content in the post message.
Maybe you are looking for WebSocket? It is basically a protocol used to send information from server to client without the need for the client to make a request. Similar to what chats systems like facebook messenger use, it stops the client having to poll a server for data.
I searched a lot of places, but couldn't find solution.
What I want to do is:
submit a form on PHP server to another server, the request is to search some results back;
The search will take several minutes, so the other server will first return a progress html page, the will page will call back to ping the other server when the final result will be returned;
Get the final result page
The function is easy if form is submitted from browser. After viewing progress page, the final search result page will be returned and shown in browser.
But I don't want to show those on my client. I want to process that on my server, process data and show something else on my client.
Thanks a lot!!
You'll need some way of tracking whether a form has been processed or not - I recommend using a database entry. So here are the basics of your algorithm:
When the user submits the form to your client, you add a new record to the DB.
The required data from this form is sent to the other server.
Any client who accesses your page will be shown the 'Waiting' layout (because the complete DB column is set to '0')
When the processing is complete, the other server hits a listener script on your server, providing it the form ID. You then update the complete column in the DB to '1'
When the user visits the page now, they see its been completed.
I'm not going to write the code for you, but this functional overview should set you on your way.
What I'm doing at the moment is creating a row in a table for each Facebook request that gets sent. Then, every time a user opens up the FB friend picker to send a request I make a call to a php file that requests information from that table and returns with a list of the FB user ids of all the people they have sent a request to in the last 24 hours. I do this for each type of request the user can send.
The issue I'm having at the moment is that if the user initiates a request, sends them off to a number of people, and then immediately opens the FB friend picker again the previous request action's records have not yet all been added to our internal table. Thus, the players, if they go fast enough, can send multiple requests to the same FB friends.
Is there a way, on the FB side, to limit this behavior Or is this entirely up to the developer to constrain? For either case, is there a recommended method by which I should achieve this behavior? Thank you.
Update
It occurred to me that our DB is keeping multiple requests from being entered on a per-user-per-24-hour period. What I do now is simply allow the second request to be made on the FB side and when the code attempts and fails to enter the second row into our DB it makes a FB Graph call that uses the app's auth_token to delete the request from Facebook itself. This means that it will show up for a moment on the receiving player's request page on Facebook but since it isn't linked with a row in the internal DB the user won't receive any reward for clicking-thru anyway.
Thanks for the suggestions, though, everybody. #Gil Birman I went ahead and accepted your answer since it's perfectly valid, even if it's not what I ultimately used to fix the problem. Thanks!
There are several ways to solve the lag problem you mentioned, one way would be to disable your send request button via javascript as soon as it is pressed. In your javascript code, instead of immediately displaying the send request dialog via FB.UI, send a json request to your server. Only when the server responds should you display the fb send request dialog. Also, the response that the server sends should include the list of friends to exclude. After the fb request is sent your javascript code should send one more json request to the server to indicate what rows in the database needs to be updated. Only when the server responds this second time should you finally re-enable your send request button.
However, there is no way to actually limit the # number of requests that your user can send. That is, no matter how well you design your javascript/php code, your user could still theoretically invoke the request dialog via the Javascript console to completely bypass your attempts to secure the app.