我是做JAVAEE的,但还没有和PHP的共存的项目的经验,但.NET是有的.
.NET负责报表部分,JAVA是业务处理,实际上,两部分除了访问同一个库外,没什么交集.
我想PHP应该不同,应该是和JAVA分担前后端的.
PHP负责展示及控制,JAVA负责业务和固化.
PHP因其执行容器原因,没办法驻留内存,高并发性能上就是个问题.
JAVA可以弥补这点.
前端上PHP可以弥补JAVA开发效率低的短板.
纯个人理解.
①首先我们写一个简单的java类并发布webservice.
package com.php;
import java.util.Map;
/**
* @author yangjuqi
*
*/
public class WebServiceImpl {
public String sendTransact(Map map) throws Exception {
System.out.println("::: Call testModel1 :::");
if(map!=null){
String bugmanifestid = StringUtil.getValue(map.get("bugmanifestid"));
String editedby = StringUtil.getValue(map.get("editedby"));
String dditeddate = StringUtil.getValue(map.get("dditeddate"));
String fullinfo = StringUtil.getValue(map.get("fullinfo"));
String action = StringUtil.getValue(map.get("action"));
System.out.println("bugmanifestid -$amp;quot;$ +bugmanifestid);
System.out.println("editedby -$amp;quot;$ +editedby);
System.out.println("dditeddate -$amp;quot;$ +dditeddate);
System.out.println("fullinfo -$amp;quot;$ +fullinfo);
System.out.println("action -$amp;quot;$ +action);
}
return "success";
②配置server-config.wsdd
deployment xmlns=""
xmlns:java=""
handler name="URLMapper"
type="java:org.apache.axis.handlers.http.URLMapper" /
handler name="auth"
type="java:com.php.AuthenticationHandler" /
handler name="URLLogging"
type="java:com.php.LogHandler"
parameter name="filename" value="c:\\MyService.log" /
/handler
service name="IWebService" provider="java:RPC"
parameter name="className"
value="com.php.WebServiceImpl" /
parameter name="allowedMethods" value="*" /
namespace;/namespace
/service
transport name="http"
requestFlow
handler type="URLMapper" /
handler type="URLLogging" /
/requestFlow
/transport
/deployment
③发布到jboss后,访问 wsdl能看到xml文件就说明webservice发布好了.
④写testphpweb.php文件
php
/*
* @author juqi yang $amp;amp;$gt;
echo " ::: PHP CALL JAVA-WEBSERVICE ::: br$amp;quot;$;
require_once("nusoap/lib/nusoap.php");
// 要访问的webservice路径
$NusoapWSDL=" wsdl";
$client = new soapclient($NusoapWSDL, true);
// 设置参数(注意:PHP只能以'数组集'方式传递参数,如果服务端是java,用Map接收)
'editedby' = '张三',
'fullinfo' = '已联系刘德华,筹备今晚吃饭的事,等待回复',
'action' = '0');
echo "begin remote ...br$amp;quot;$;
// 调用远程方法
$result = $client-call('sendTransact', array($param));
echo "end remote ...br$amp;quot;$;
// 显示执行结果
if (!$err=$client-getError()){
echo '结果 : '.$result;
}else{
echo '错误 : '.$err;
⑤启动apache,访问
php页面显示:
::: PHP CALL JAVA-WEBSERVICE :::
begin remote ...
end remote ...
结果 : success
jboss后台监视结果:
①编写php webservice
function sendManifest($param)
{
//把接收到的数据显示出来
return "hello ".$param["projectid"]."=$amp;quot;$.$param["projectname"]."=$amp;quot;$.$param["moduleid"];
$server = new nusoap_server();
//配置WSDL namespace
$server-configureWSDL('myservice', //服务名称
'', //tns指定的namespace,一般填写自己的URI
true, //endpoint url or false
'rpc', //服务样式
'', //传输协议,一直是这个.
'' //wsdl 'types'元素targetNamespace
);
// 注册web服务
$server-register('sendManifest', // 服务
array(
'projectid' = 'xsd:string',
'projectname' = 'xsd:string',
'moduleid' = 'xsd:string',
'modulepath' = 'xsd:string',
'bugtitle' = 'xsd:string',
'bugtype' = 'xsd:string',
'openedby' = 'xsd:string',
'openeddate' = 'xsd:string',
'assignedto' = 'xsd:string',
'assigneddate' = 'xsd:string',
'fixedtime' = 'xsd:string',
'fullinfo' = 'xsd:string',
'bugmanifestid' = 'xsd:string'), // 输入参数;数组,指定类型
array('resultCode' = 'xsd:string'), // 输出;数组,指定类型
'', // namespace of method
'', // soapaction
'rpc', // style
'encoded', // use
'serviceConsumeNotify' // documentation
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) $HTTP_RAW_POST_DATA : '';
$server-service($HTTP_RAW_POST_DATA);
②启动apache后,访问 ,如果页面如下图所示,表示webservice发布好了.
import java.util.HashMap;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class CallPhpServer {
* 测试方法
* @return
* @throws Exception
public static String callManifest() throws Exception {
System.out.println("0");
Service service = new Service();
Call call = (Call) service.createCall();
System.out.println("1");
call.setTargetEndpointAddress(new java.net.URL(""));
call.setOperationName("sendManifest");
Map map=new HashMap();
map.put("moduleid", "11");
map.put("bugtype", "TrackThings");
map.put("openedby", "zhangsan");
map.put("assignedto", "liumang");
call.addParameter("param", org.apache.axis.Constants.SOAP_ARRAY,javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.Constants.XSD_STRING);
Object obj=call.invoke(new Object[]{map});
return obj.toString();
public static void main(String[] args) throws Exception {
System.out.println("::: call php webservice :::");
String str = callManifest();
System.out.println(result);
控制台显示结果:
::: call php webservice :::
①.
②.
③.
PHP+JAVA的架构,特别是对于有复杂的用户交互及高并发及后端还有复杂的业务的网站来说,如电商类网站,前端用PHP,可以做到快速开发,部署不用重启,同时nginx + fastcgi + php的组合也是经得起高并发考验的.后端的复杂业务处理(如订单处理,购物车,库存相关的)使用java来做实在是太合适了.不信你可以试试!
以上就是土嘎嘎小编为大家整理的php融合到javaweb中相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!