php - Porting lighttpd server to Android -
i trying port lighttpd android uses can execute php script there android device hitting localhost:port broswser script not working properly
here runtime java code
invoked when user clicks on buttonpublic class runtimeprovider { boolean isloaded = false;
processbuilder mysqlbuilder = new processbuilder(new string[] { "/data/data/com.punk.qs/mysqld", "--defaults-file=/data/data/com.punk.qs/my.ini", "--user=root", "--language=/data/data/com.punk.qs/share/mysql/english" }); processbuilder phpbuilder = new processbuilder(new string[] { "/data/data/com.punk.qs/php-cgi-ext", "-c", "data/data/com.punk.qs/php.ini" }); processbuilder lighttpdbuilder = new processbuilder(new string[] { "/data/data/com.punk.qs/lighttpd", "-f", "data/data/com.punk.qs/lighttpd.conf" }); public void execute() { file fphp = new file("/data/data/com.punk.qs/php-cgi-ext"); file flighttp = new file("/data/data/com.punk.qs/lighttpd"); file fmysql = new file("/data/data/com.punk.qs/mysqld"); if (fphp.exists() && flighttp.exists() && fmysql.exists()) { try { runtime.getruntime().exec( "chmod 777 /data/data/com.punk.qs/lighttpd"); lighttpdbuilder.start(); //nativeapp( "/data/data/com.punk.qs/lighttpd -f data/data/com.punk.qs/lighttpd.conf", "lighttpd"); log.w("lighttpd started ", "lighttpd started"); } catch (ioexception e) { log.w("lighttpd startup failed ", e); new errorlogger("lighttpd", e.tostring()); } try { runtime.getruntime().exec( "chmod 777 /data/data/com.punk.qs/mysqld"); mysqlbuilder.start(); //nativeapp( "/data/data/com.punk.qs/mysqld --defaults-file=/data/data/com.punk.qs/my.ini --user=root --language=/data/data/com.punk.qs/share/mysql/english", "mysql"); log.d("mysql started ", "mysql started"); } catch (ioexception e) { log.w("mysql startup failed ", e); new errorlogger("mysql", e.tostring()); } try { runtime.getruntime().exec( "chmod 777 /data/data/com.punk.qs/php-cgi-ext"); phpbuilder.start(); //nativeapp( "/data/data/com.punk.qs/php-cgi-ext -c data/data/com.punk.qs/php.ini", "phpcgi"); log.d("php started ", "php started"); } catch (ioexception e) { log.w("php startup failed ", e); new errorlogger("phpcgi", e.tostring()); } } else { log.w("error runime lib", "runtime libs missing"); } // return b; } public void nativeapp(string cmd, string tag) { process nativeapp = null; log.d("executing :", cmd); try { nativeapp = runtime.getruntime().exec(cmd); } catch (ioexception e) { log.e("runtime error : ", e.tostring()); new errorlogger("runtime", e.tostring()); } bufferedreader reader = new bufferedreader(new inputstreamreader( nativeapp.getinputstream())); int read; char[] buffer = new char[4096 * 8]; stringbuffer output = new stringbuffer(); try { while ((read = reader.read(buffer)) > 0) { output.append(buffer, 0, read); } reader.close(); } catch (ioexception e) { log.e("io error : ", e.tostring()); new errorlogger("io", e.tostring()); } // waits command finish. try { nativeapp.waitfor(); } catch (interruptedexception e) { log.e("interruptedexception : ", e.tostring()); new errorlogger("intexp", e.tostring()); } string nativeoutput = output.tostring(); if (nativeoutput != null) isloaded = true; log.d("output : " + cmd, nativeoutput); new errorlogger("runlib", nativeoutput); }
}
method runtimeprovider().execute()
the best way go opensource project this , go through code copy assets
, check on device or emulator have used project use php
, lighthttpd
in android..
Comments
Post a Comment