Skip to content


在 Android 手机上运行 PHP

PHP可不仅仅只能在互联网站上发展,一个PHP for Android (PFA)网站表示他们将可以发布编程模型、工具盒文档让PHP在Android上实现应用。该项目的主要赞助商是开源公司IronTec,PFA使用Scripting Layer for Android (SL4A),也就是Androd Scripting Environment (ASE)来实现这一点,您可以参看他们的网站来了解更多技术内幕。

1.下载并安装ASE
扫描下面的二维码,可在你的手机上安装个条码扫描器(BarcodeScanner)

或用浏览器下载并安装
http://phpforandroid.net/files/ASEr26unofficial.apk

2.安装PhpForAndroid.apk

或用浏览器下载并安装
http://phpforandroid.net/files/PhpForAndroid_r1.apk

3.运行
安装好PhpForAndroid_r1.apk后再运行ASE就可以看到5个php demo
hello_world.php

getInput(“Hi!”, “What is your name?”);
$droid->makeToast(‘Hello, ‘ . $name[‘result’]);

list_items.php

dialogCreateAlert();
$droid->dialogSetItems(range(0, 9));
$droid->dialogShow();

phpinfo.php

testnow.php

vibrate.php

vibrate();

点击phpinfo.php文件开始运行;
程序会输出php的相关信息,当前使用的php版本为5.3.3rc2

$ export TEMP=”/sdcard/ase/extras/php/tmp”
$ export AP_PORT=”37356″
$ export PHPHOME=”/data/data/com.irontec.phpforandroid/php”
$ export PHPPATH=”/sdcard/ase/extras/php”
$ /data/data/com.irontec.phpforandroid/php/bin/php -c $PHPPATH /sdcard/ase/scripts/phpinfo.php
FIX ME! implement getprotobyname() bionic/libc/bionic/stubs.c:402
FIX ME! implement getprotobyname() bionic/libc/bionic/stubs.c:402
phpinfo()
PHP Version => 5.3.3RC2
System => Linux localhost 2.6.29.6-xdan #20 PREEMPT Sat Mar 27 03:36:57 EDT 2010 armv6l
Build Date => Jul 4 2010 19:40:10
Configure Command => ‘./configure’ ‘–disable-all’ ‘–target=arm-linux’ ‘–enable-cli’ ‘–enable-json’ ‘–enable-sockets’
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /sdcard/ase/extras/php/php.ini
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
PHP API => 20090626
PHP Extension => 20090626
Zend Extension => 220090626
Zend Extension Build => API220090626,NTS
PHP Extension Build => API20090626,NTS
Debug Build => no
Thread Safety => disabled
Zend Memory Manager => enabled
Zend Multibyte Support => disabled
IPv6 Support => disabled
Registered PHP Streams => php, file, data, http, ftp
Registered Stream Socket Transports => tcp, udp, unix, udg
Registered Stream Filters => string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
_______________________________________________________________________
Configuration
Core
PHP Version => 5.3.3RC2
Directive => Local Value => Master Value
allow_call_time_pass_reference => On => On
allow_url_fopen => On => On
allow_url_include => On => On
always_populate_raw_post_data => Off => Off
arg_separator.input => & => &
arg_separator.output => & => &
asp_tags => Off => Off
auto_append_file => no value => no value
auto_globals_jit => On => On
auto_prepend_file => no value => no value
browscap => no value => no value
default_charset => no value => no value
default_mimetype => text/html => text/html
define_syslog_variables => Off => Off
disable_classes => no value => no value
disable_functions => no value => no value
display_errors => STDOUT => STDOUT
display_startup_errors => On => On
doc_root => no value => no value
docref_ext => no value => no value
docref_root => no value => no value
enable_dl => Off => Off
error_append_string => no value => no value
error_log => no value => no value
error_prepend_string => no value => no value
error_reporting => 22527 => 22527
exit_on_timeout => Off => Off
expose_php => On => On
extension_dir => /usr/local/lib/php/extensions/no-debug-non-zts-20090626 => /usr/local/lib/php/extensions/no-debug-non-zts-20090626
file_uploads => On => On
highlight.bg => #FFFFFF => #FFFFFF
highlight.comment => #FF8000 => #FF8000
highlight.default => #0000BB => #0000BB
highlight.html => #000000 => #000000
highlight.keyword => #007700 => #007700
highlight.string => #DD0000 => #DD0000
html_errors => Off => Off
ignore_repeated_errors => Off => Off
ignore_repeated_source => Off => Off
ignore_user_abort => Off => Off
implicit_flush => On => On
include_path => .:/sdcard/ase/extras/php => .:/sdcard/ase/extras/php
log_errors => Off => Off
log_errors_max_len => 1024 => 1024
magic_quotes_gpc => Off => Off
magic_quotes_runtime => Off => Off
magic_quotes_sybase => Off => Off
mail.add_x_header => Off => Off
mail.force_extra_parameters => no value => no value
mail.log => no value => no value
max_execution_time => 0 => 0
max_file_uploads => 20 => 20
max_input_nesting_level => 64 => 64
max_input_time => -1 => -1
memory_limit => 128M => 128M
open_basedir => no value => no value
output_buffering => 0 => 0
output_handler => no value => no value
post_max_size => 8M => 8M
precision => 14 => 14
realpath_cache_size => 16K => 16K
realpath_cache_ttl => 120 => 120
register_argc_argv => On => On
register_globals => Off => Off
register_long_arrays => Off => Off
report_memleaks => On => On
report_zend_debug => Off => Off
request_order => GP => GP
safe_mode => Off => Off
safe_mode_exec_dir => no value => no value
safe_mode_gid => Off => Off
safe_mode_include_dir => no value => no value
sendmail_from => no value => no value
sendmail_path => /usr/sbin/sendmail -t -i => /usr/sbin/sendmail -t -i
serialize_precision => 100 => 100
short_open_tag => On => On
SMTP => localhost => localhost
smtp_port => 25 => 25
sql.safe_mode => Off => Off
track_errors => Off => Off
unserialize_callback_func => no value => no value
upload_max_filesize => 2M => 2M
upload_tmp_dir => no value => no value
user_dir => no value => no value
user_ini.cache_ttl => 300 => 300
user_ini.filename => .user.ini => .user.ini
variables_order => GPCS => GPCS
xmlrpc_error_number => 0 => 0
xmlrpc_errors => Off => Off
y2k_compliance => On => On
zend.enable_gc => On => On
date
date/time support => enabled
“Olson” Timezone Database Version => 2010.9
Timezone Database => internal
Warning: phpinfo(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Chicago’ for ‘CST/-CST/no DST’ instead in /sdcard/ase/scripts/phpinfo.php on line 4
Default timezone => America/Chicago
Directive => Local Value => Master Value
date.default_latitude => 31.7667 => 31.7667
date.default_longitude => 35.2333 => 35.2333
date.sunrise_zenith => 90.583333 => 90.583333
date.sunset_zenith => 90.583333 => 90.583333
date.timezone => no value => no value
ereg
Regex Library => Bundled library enabled
json
json support => enabled
json version => 1.2.1
pcre
PCRE (Perl Compatible Regular Expressions) Support => enabled
PCRE Library Version => 8.02 2010-03-19
Directive => Local Value => Master Value
pcre.backtrack_limit => 100000 => 100000
pcre.recursion_limit => 100000 => 100000
Reflection
Reflection => enabled
Version => $Revision: 300393 $
sockets
Sockets Support => enabled
SPL
SPL support => enabled
Interfaces => Countable, OuterIterator, RecursiveIterator, SeekableIterator, SplObserver, SplSubject
Classes => AppendIterator, ArrayIterator, ArrayObject, BadFunctionCallException, BadMethodCallException, CachingIterator, DirectoryIterator, DomainException, EmptyIterator, FilesystemIterator, FilterIterator, InfiniteIterator, InvalidArgumentException, IteratorIterator, LengthException, LimitIterator, LogicException, MultipleIterator, NoRewindIterator, OutOfBoundsException, OutOfRangeException, OverflowException, ParentIterator, RangeException, RecursiveArrayIterator, RecursiveCachingIterator, RecursiveDirectoryIterator, RecursiveFilterIterator, RecursiveIteratorIterator, RecursiveRegexIterator, RecursiveTreeIterator, RegexIterator, RuntimeException, SplDoublyLinkedList, SplFileInfo, SplFileObject, SplFixedArray, SplHeap, SplMinHeap, SplMaxHeap, SplObjectStorage, SplPriorityQueue, SplQueue, SplStack, SplTempFileObject, UnderflowException, UnexpectedValueException
standard
Dynamic Library Support => enabled
Path to sendmail => /usr/sbin/sendmail -t -i
Directive => Local Value => Master Value
assert.active => 1 => 1
assert.bail => 0 => 0
assert.callback => no value => no value
assert.quiet_eval => 0 => 0
assert.warning => 1 => 1
auto_detect_line_endings => 0 => 0
default_socket_timeout => 60 => 60
safe_mode_allowed_env_vars => PHP_ => PHP_
safe_mode_protected_env_vars => LD_LIBRARY_PATH => LD_LIBRARY_PATH
url_rewriter.tags => a=href,area=href,frame=src,form=,fieldset= => a=href,area=href,frame=src,form=,fieldset=
user_agent => no value => no value
Additional Modules
Module Name
Environment
Variable => Value
ANDROID_ROOT => /system
PHPPATH => /sdcard/ase/extras/php
LD_LIBRARY_PATH => /system/lib
PATH => /usr/bin:/usr/sbin:/bin:/sbin:/system/sbin:/system/bin:/system/xbin:/system/xbin/bb:/data/local/bin
AP_PORT => 37356
ANDROID_SOCKET_zygote => 11
TEMP => /sdcard/ase/extras/php/tmp
BOOTCLASSPATH => /system/framework/core.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar
ANDROID_BOOTLOGO => 1
ANDROID_ASSETS => /system/app
EXTERNAL_STORAGE => /sdcard
ANDROID_DATA => /data
TERMINFO => /system/etc/terminfo
ANDROID_PROPERTY_WORKSPACE => 10,32768
PHPHOME => /data/data/com.irontec.phpforandroid/php
PHP Variables
Variable => Value
_SERVER[“ANDROID_ROOT”] => /system
_SERVER[“PHPPATH”] => /sdcard/ase/extras/php
_SERVER[“LD_LIBRARY_PATH”] => /system/lib
_SERVER[“PATH”] => /usr/bin:/usr/sbin:/bin:/sbin:/system/sbin:/system/bin:/system/xbin:/system/xbin/bb:/data/local/bin
_SERVER[“AP_PORT”] => 37356
_SERVER[“ANDROID_SOCKET_zygote”] => 11
_SERVER[“TEMP”] => /sdcard/ase/extras/php/tmp
_SERVER[“BOOTCLASSPATH”] => /system/framework/core.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar
_SERVER[“ANDROID_BOOTLOGO”] => 1
_SERVER[“ANDROID_ASSETS”] => /system/app
_SERVER[“EXTERNAL_STORAGE”] => /sdcard
_SERVER[“ANDROID_DATA”] => /data
_SERVER[“TERMINFO”] => /system/etc/terminfo
_SERVER[“ANDROID_PROPERTY_WORKSPACE”] => 10,32768
_SERVER[“PHPHOME”] => /data/data/com.irontec.phpforandroid/php
_SERVER[“PHP_SELF”] => /sdcard/ase/scripts/phpinfo.php
_SERVER[“SCRIPT_NAME”] => /sdcard/ase/scripts/phpinfo.php
_SERVER[“SCRIPT_FILENAME”] => /sdcard/ase/scripts/phpinfo.php
_SERVER[“PATH_TRANSLATED”] => /sdcard/ase/scripts/phpinfo.php
_SERVER[“DOCUMENT_ROOT”] =>
_SERVER[“REQUEST_TIME”] => 1279269078
_SERVER[“argv”] => Array
(
[0] => /sdcard/ase/scripts/phpinfo.php
)
_SERVER[“argc”] => 1
PHP License
This program is free software; you can redistribute it and/or modify
it under the terms of the PHP License as published by the PHP Group
and included in the distribution in the file: LICENSE
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If you did not receive a copy of the PHP license, or have any
questions about PHP licensing, please contact license@php.net.

运行结束后就是控制台界面,按menu键会出来Exit&Edit可以进入编辑模式;
编辑模式下有API Browser可供调用,save & Run就可以调试程序了。
在我的g1,1.6固件上运行正常。

安装教程
http://www.phpforandroid.net/screencast

Posted in Android, 其它.

Tagged with , , .


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. 灯杆 says

    呵呵,强悍。。



Some HTML is OK

or, reply to this post via trackback.