LINUX php 安装soap模块
如果是yum 安装的php 要安装soap模块 直接yum install php-soap即可 然后重启服务
from :
http://liveforlinux.blog.51cto.com/3337218/620737
- 首先安装完php后最好保留当时安装的文件,比如我的路径/usr/local/php-5.3.5/
- cd php-5.3.5/ext/soap
- /usr/local/php/bin/phpize
- ./configure --with-php-config=/usr/local/php/bin/php-config --enable-soap
- make
- make install
- 编译后的soap.so文件保存在了目录下
- 修改php.ini文件 vi /usr/local/php/lib/php.ini
- 手工修改:查找/usr/local/php/lib/php.ini中的extension_dir = "./"
- 修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
- 并在此行后增加如下,然后保存:
- extension = "soap.so"
- 重新启动/etc/init.d/php-fpm reload,ok
- root@russia-dress soap]# php -m
- [PHP Modules]
- Core
- ctype
- curl
- date
- dom
- eAccelerator
- ereg
- fileinfo
- filter
- gd
- hash
- iconv
- json
- libxml
- mbstring
- mcrypt
- mhash
- mysql
- openssl
- pcre
- PDO
- pdo_sqlite
- Phar
- posix
- Reflection
- session
- SimpleXML
- soap
- sockets
- SPL
- SQLite
- sqlite3
- standard
- tokenizer
- xml
- xmlreader
- xmlwriter
- zip
- zlib
- [Zend Modules]
- eAccelerator
- 我们就已经能看到扩展的soap模块了。
- 如果是yum 安装的php 要安装soap模块 直接yum install php-soap即可 然后重启服务
- 我的LINUX系统是YUM安装
- --有些系统是php_soap.so
- 我的系统(centos)路径是./usr/lib64/php/modules/soap.so,路径要注意
- 在etc/php.ini
- 添加:
- extension = php_soap.soextension_dir = "/usr/lib64/php/modules/"
- php -m 之后可以看到SOAP 证明已经配置好了
- web service开发:
- 以下来自:http://www.2cto.com/kf/201202/118601.html
-
clientsoap.php:
-
<?php
try {
$client = new SoapClient(null,
array('location' =>"http://105.14.19.7/test/serversoap.php",'uri' => "http://127.0.0.1/")
);
echo $client->minus_func(100,99);} catch (SoapFault $fault){
echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;
}
?> -
serversoap.php:
-
$soap = new SoapServer(null,array('uri'=>" http://114.27.19.7/"));//This uri is your SERVER ip.
$soap->addFunction('minus_func'); //Register the function
$soap->addFunction(SOAP_FUNCTIONS_ALL);
$soap->handle();
/*
$soap->addFunction('add'); //Register the function
$soap->addFunction(SOAP_FUNCTIONS_ALL);
$soap->handle();
*/
function minus_func($i, $j){
$res = $i - $j;
return $res;
}
/*
function add($i, $j){
$res = $i + $j;
return $res;
}*/
?>
测试结果:1 -
这是客户端调用服务器端函数的例子,我们再搞个class的。
clientsoap.php: -
<?php
//client端clientSoap.php
try
{
$client = new SoapClient(null,
array('location' =>"http://114.28.19.7/test/serversoap.php",'uri' => "http://127.0.0.1/")
);
echo $client->getName();
}
catch (SoapFault $fault)
{
echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;
}?>
serversoap.php:
-
<?php
//www.2cto.com server端serverSoap.php
$classExample = array();
$soap = new SoapServer(null,array('uri'=>" http://114.28.19.7/",'classExample'=>$classExample));
$soap->setClass('chesterClass');
$soap->handle();
class chesterClass
{
public $name = 'Chester';
function getName()
{
return $this->name;
}
}
?> -
测试结果:Chester
DOMDocument封装XML遇到的问题:
Fatal error: Class 'DomDocument' not found in
yum install php-xmlservice httpd restart
MAC OS 不需要安装 SOAP,只要配置好PHP+APACHE