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?
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.
I'm coding a small yet useful app to serve as an end-Point of HTML Forms, to avoid manually code every time I want to save Forms submissions into Database. Because of the nature of the app, I want to store all the POST's fields sent by the HTML form that sends the request.
This is my approach:
- User in the app creates an endpoint to send form submissions every endpoint will be stored in a table called ENDPOINTS that will have 2 fields: endpoint_URL (plain text to create the HTML endpoint) | data sent (JSON text to receive every field sent, no matter if every submission has different fields) this way I can store all the information without altering the structure of the Database Table every time a new field is received.
-The app then can show an HTML table of the specific endpoint and the information received field and content.
My concerns are:
-every submission (no matter if the submission comes from different endpoints) will be stored in the same database table, therefore it can create a huge list of registries on a single table.
Every time the HTML table is created will need to take the JSON content of the database field and reconstruct the HTML table (instead of using the power of the database to this endeavor).
What do you think could be the best approach to accomplish this? I can think on make a new table every time an endpoint is created and this table will receive every submission of the propper endpoint, nonetheless using this approach needs the database to update the fields every time the form receives different fields from the same endpoint.
I'm using LUMEN Framework instead of plain PHP to focus on the logic of the app rather than security concerns.
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']";?>
My Yii2 based application has a process where I need to fetch data from an external SOAP API and display the results after processing. I wish to display some static data and a placeholder for results until the background process of API data fetch and processing is completed.
Is there a way to display intermediate data in Yii2 views without using Ajax? Ajax is not a suitable option in this case due to amount of data which needs to be exchanged with API, and processed before rendering the results. Plus, results format is variable, and hence different templates may need to be applied before rendering them.
EDIT: to give a clearer picture, the flow is as below:
User Submits data (UD)
Data is processed onto the server resulting in information (SI) and data (SD)
SD is submitting to external SOAP API which returns information (AI)
User shall be given the two pieces of information SI and AI, however user shouldn't be able to see the data SD at any point
Server side processing takes about 1 second, however API data interchange takes about 15 seconds
So, SI is available at t=1 sec, but AI is only available after t=16 secs. The purpose here is to not make the user wait for AI availability, and give them time to consume SI, while AI is provided when it becomes available.
So the question is a little complicated, let me explain. My page code is running like this:
User enters query in the search field and clicks submit.
1.1 jQuery loads a new body to display progress data.
1.2 jQuery calls process.php via AJAX and supplies query as the argument.
1.3 jQuery starts setInterval periodic update to grab progress data, stored inside $_SESSION['prog'], and displays it.
When process.php finishes, jQuery stops periodic update, displays final information and calls AJAX to clear the $_SESSION['prog'] variable.
At the moment progress data is stored inside one variable, which is fine as far as different users are concerned (because of the different sessions), but if the same user were to make multiple requests at the same time, the $_SESSION['prog'] variable would be cross-overwritten.
So far I have thought of two possiblities to distinguish data for each request from the same user (same session)
Have jQuery generate some random string and send it together with query (and hope to avoid colission, although that would be unlikely)
Make 2 AJAX calls, first one requesting new_request_id, the second one sending query and new_request_id as parameters.
Have AJAX return something from PHP before is finishes(completes).
I need to connect each browser window (each request) with each running process, so I cannot send back new request ID after the request has been submitted, because I wont know which data to pick up with jQuery in the browser window. Btw, I will change $_SESSION['prog'] to $_SESSION[request_id] -> request_id is what I'm looking for.
It (request_id) could be last_insert_id(), because im creating new DB entries for each valid query, but I don't know how to get it back to each different user window.
I need advice here. Only just begun to code in PHP, AJAX and jQuery, don't really know much about sessions. How should I solve this problem?
Sorry for the lack of code, I will paste is at request.
You could add a unique ID to each request in addition to the session ID. eg. uniqid() in javascript/jquery?
You need to differentiate them somehow. For example use a unique ID autonumber field. MySQL has last_insert_id() which is very useful and handles concurrent requests correctly.
Avoid using Session variables in Ajax requests. Send them with GET (or POST) instead. Even if calling Session_start(); in the Ajax request and getting $_SESSION['prog'] from there, results can be unexpected.