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.
Related
Background
I have an iOS app that retrieves data from a server and writes it to a file with NSFileManager, so that the user does not have to retrieve data again from the server every time they want to visit a page. The data that they are retrieving can change from time to time, so I would like to update the data in the app files when it does.
I am using php pages for my backend web services.
Question
What is the technique for checking if the data in my database has changed so that I know that I should update the data in the app? The only way I can think to do this is to create a php page that checks if the data is different from what I have stored, but this kind of defeats the purpose of saving information to files within the app. I want to minimize when the user communicates with the server, because in situations where the user has no service, I would still like there to be valid data that they can see within the app.
Please ask questions if you do not fully understand what I am trying to achieve. Thank you!
If you want to list the most recently added restaurants for example, you could :
Store the ID of the most recent restaurant on IOS and send it to the server when you want to check for updates.
If the ID isn't the same in the DB, then you have to update your client.
If it's the same, you can just send a response with a 304 status (Not modified) so you minimise the amount of data being exchange.
If you want to cache computed data, like top 10 user-rated restaurants, you can :
Store a hash of the 10 restaurant IDs and send it to server when you want to check for updates.
The server redo the request and compute the current hash for the top 10.
If the hash is different, update your client
If the hash is the same, send a response with a 304 status
NB : If the computation is expensive on server side, you might want to think about a more clever way to detect data changes.
In this case you need to define your release ID on server and store somewhere in app as well. For example, when you do some changes in database or there is an update from server side. Just change that release ID from server.
On IOS side you need to check that release ID. If ios release id is lower than server's ID, then update your database in ios local storage.
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 am developing a UI framework in PHP. The idea is very similar to .NET platform. Different php class are developed to render DOJO controls. In short the framework generates Javascript code to render DOJO UI controls on client side. The process is as follows:
First Request:
URL GET request come to server.
Server executes the relevant scripts which load the FORM.
Call render function of each child control (this generates the
javascript code)
serialize the whole FORM object and save it to a SESSION file.
Output the JS Code to client.
Subsequent Requests:
FORM postback request comes to server.
Server loads previous state from SESSION file (using unserialize).
Update the state object with user submitted values.
Call event handlers.
Save the current state in SESSION file.
Render response to client.
The above process works perfect for a single request at a time from same session. I need to handle multiple requests from the same session at a time.
Issue:
Let say there are two requests from the same session R1 and R2
respectively. R1 takes 10 secs to complete while R2 takes 3 secs. While
R1 was at 5 secs R2 comes and update the state file when R1 is at 8
Sec. After that R1 updates the state file again after 2 secs.
The problem is that the changes made by request R2 to state file is lost.
How the above scenario could be handled in PHP? Is there any design pattern I can follow for state management in UI framework?
Generate a unique key each time the form is requested (GET) and put it into the form as a hidden input field. This is a common practice to mitigate CSRF attacks, so you can also use it to see which form post relates to each GET request. Maybe it'll be the key to your forms array stored in your session.
Side note: it seems excessive to store some serialized form data with the session on every GET request. In most cases your form would be identical across all users. And on the POST you would presumably know what the form should "look" like anyway (although I imagine you're doing this to generalize the form handler).
i am building payment form
and want auto select credit card type with the 1st 4 digits
i have the valid ranges on Visa Master AMEX Discover
here an example of Discover one
validRanges":["6282","6283","6284","6285","67","66","6287","6286","6288","64","65","63888","6011","622","624","625","626"]
how may i build input that auto select discover card and appear the discover icon
and disapper other ones
somethink like this
https://www.panic.com/coda/buy.html
You are surely going to need Javascript for that kind of effect. And assuming you are storing that data on the server (possibly in the database) you'll need AJAX to query the database and find out if the inputted digits are part of any range in the database.
For the Javascript part I suggest you to take a look at jQuery: specifically jQuery.ajax() and the function .fadeTo().
The basic idea you are going to implement is basically the following:
Detect any user digit input
Take the <input> input and send it (via AJAX) to a PHP script x.php
x.php processes the inputted data (possibly sent via POST method) and queries the database returning a JSON array of card types to the client side
The client side convert the JSON string to actual JSON objects and use it to hide or show specific divs representing the cards.
I have the following dilemma, I have an Android Application that POST a request into a mysql db via php using HTTP Client, I'm using JSON to extract the response.
Here's a rough view of that scenario,
I have a ArrayList that gets populated using the response, lets call it the Main Menu
Upon clicking an item from the Main Menu, I would send a POST request and wait for the response from the server,
So here's my question, which one is advisable and more reliable,
Upon running the application/activity, I would download everything and hide the irrelevant items, enabling/disabling them upon request, eg. I'm just showing the first relevant items for the Menu, or
Request to the server the information details of the selected Menu Item only upon request? Like, just download the Main Menu, and the default items for the Main Menu id 1
Are there any other available approach, what are the pros and cons of each approach, which one is reliable and more efficient?
Depends on the length of the list but some things to consider...
How long is it going to take to retrieve and populate the menu before the user gets a response?
Latency is the killer in mobile (3G, 2G etc), so one larger request may be quicker than multiple smaller ones.
Multiple smaller requests will consume more battery power as the phone will have to wake the radio from sleep and this is consumes more power than waking one and a larger response. (there was some good research published on this recently)