Run php script stored in the server?

14,621

Solution 1

Simply perform HTTP get request:

String url = "http://your.domain.com/path/to/file.php";
HttpClient client = new DefaultHttpClient();

try {
  client.execute(new HttpGet(url));
} catch(IOException e) {
  //do something here
}

Solution 2

There are various ways to do that 1. You can call the script using webrequest.create from your application Or you can use CURL in case of php application 2. You can execute the script using cron job and schedule it to run according to your need

Link 1

Link 2

Share:
14,621
androniennn
Author by

androniennn

Updated on June 04, 2022

Comments

  • androniennn
    androniennn about 2 years

    I have a php script stored in Wamp server, and want that my application execute it to perform some image treatement from server then the server send the result to the Android phone. Is that possible to perform ? And please if so can you give some hints?

    Thank you very much.

  • androniennn
    androniennn over 12 years
    Here is a good answer. But please if you have some links post them :). Thank you very much.
  • androniennn
    androniennn over 12 years
    Thank you very much. The problem is the php script will "output" an image (that was treated), how to "take" it and display it in the Android phone? Thanks :).
  • njzk2
    njzk2 over 12 years
    client.execute return a nice object that represent the result. which contains everything you need (http status, content-length, content it self, ...)
  • androniennn
    androniennn over 12 years
    @njzk2: be patient please: you informed me that i have to use a push mechanism like c2DM to retrieve the data. Here you write that client.execute return the result of executing the script(content it self). Right? C2DM? client.execute? a little bit confused. Thank your for helping.
  • Koby Hastings
    Koby Hastings over 12 years
  • njzk2
    njzk2 over 12 years
    there are always various ways of doing things. If your treatement is a long (more than, says, 60 seconds) one, you may consider doing it on the server and notifiying the client later. that is where push mechanisms like C2DM come into play. However, you should probably start with simple HTTP requests, using the code provided by ioseb. See HttpResponse documentation. for how to handle the result.
  • njzk2
    njzk2 over 12 years
    what is webrequest.create here? (and what does it have to do with android?)
  • androniennn
    androniennn over 12 years
    @njzk2: a very good answer, that is clearer now ;). So client.execute will return the treated image. Optimisations? We can thing about other technics ;). Thanks :).