我的项目前期用CakePHP开发了一个前台的网站,现在需要在PHP中直接访问Nutch的API接口,很是头痛,这几天一直在调研和Demo。
其实都是前人已经做过的事情,我只是把他们整合起来。
第一步,需要利用JAX-WS架设一个Web服务,参见IBM的一篇文章
第二步,写了一个PHP的Demo程序,如下:
<?php // DON'T CACHE the SOAP on the PHP server $ini = ini_set("soap.wsdl_cache_enabled","0"); $client = new SoapClient("http://localhost:8080/OrderProcessWeb/orderprocess?wsdl", array("user_agent"=>"some_string")); //your parameter to send $p = array('arg0' => 'hello world, this is royal'); //the soap function might require nested type try{ $ret = $client->processOrder($p); print json_encode($ret); //or var_dump($ret); print "<pre>"; var_dump($client->__getFunctions()); var_dump($client->__getTypes()); } catch (SoapFault $exception) { print 'SOAP Error '; print json_encode($exception); //or var_dump($exception); } ?>
其中$p是一个参数数组,里面的参数名称arg0需要和OrderProcess_schema1.xsd中的名称保持一致。