Send Php File1 Response To Android Immediately And Then Call Another Php File2 From File1
I call file1.php from android and I want it to send xml response to android and immediately after that call file2.php from file1.php. I also want to send an array from file1.php to file2.php. How can this be done without delaying sending the response to android as android needs response only from file1. But file2 input is file1's output. So is there a way in which i can send file1's xml output to android and then call file2 immediately after that?
Details : Android :-> Display near by restaurants using google places api.
File1.php :-> Get the list of near by restaurants google places api and send it to android. Immediately after this I want to call File2.php from File1.php where I send the reference id's of the restaurants(o/p of File1) so that i can get each restaurants details.
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("latitude",latt)); nameValuePairs.add(new BasicNameValuePair("longitude", longi)); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost("http://www.xyz.com/file1.php"); httpPost.setEntity(new UrlEncodedFormEntity (nameValuePairs)); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); line = EntityUtils.toString(httpEntity);
$url = 'https://maps.googleapis.com/maps/api/place/search/xml?....'; //get xml response and send it to android //call file2.php and send reference id's so as ot get each restaurant details
for(each restaurant) //get details and do some back end processing.
Main thing is android should receive response before file2 starts executing.
You can't execute an external php-file (that is actually make a new http-request) in parallel to existing request-response flow. There exist 2 possible solutions.
You can implement a task queue on your server (usually a dedicated table in DB), so while processing a request by
file1.phpyou should add new task in the queue. In parallel to main web-server process, you should have a php "daemon" always running, which looks for new tasks and processes them in background (fetches required details by
file2.php). Once a task is ready (or a part of it, for example several first records with details are available), mark it appropriately in the queue. Android app should periodically check new details and load them using another access point (say
file3.php), which returns available details from partially or completely executed task. I don't know which server-side framework do you use (if any), but some of them provide "batch jobs" based on
cron. This looks not as easy to go way though. Most appropriate method would be to use push notification, that is the server should notify your client about new available details for items in the list already sent to the client.
You can move part of control logic into the Android app. This way it requests a list of objects, then in a loop send new requests for object details, which are proxied to Google Places by means of
file2.php. In other words,
file2.phpis executed by client instead of the server.
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?