Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3144
  • 博文数量: 7
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2014-12-18 11:18
文章分类
文章存档

2014年(7)

我的朋友
最近访客

分类: PHP

2014-12-18 11:23:21

原文地址:yii中soap接口调用修改 作者:nuoyazhou110

如果服务器安装了eAccelerator, 默认优化的时候删除了PHP的文档块并缓存代码编译结果,所有调用反射接口的时候返回false ,导致yii调用wsdl文件找不到方法.

现修改代码如下:

CWebService.php  中 generateWsdl方法


	public function generateWsdl()
	{
		$providerClass=is_object($this->provider) ? get_class($this->provider) : Yii::import($this->provider,true);
		$key='Yii-CWebService-'.$providerClass.'.txt';
		$generator=new CWsdlGenerator;
		$wsdl=$generator->generateWsdl($providerClass,$this->serviceUrl,$this->encoding);

		//wsdl dir
		$wsdl_cache_dir = './protected/wsdl/';
		if(!is_dir($wsdl_cache_dir))
		{
			mkdir($wsdl_cache_dir);
		}
		//get file update time
		$php_class_file_path = './protected/controllers/'.$providerClass.'.php';
		$last_up_time = filemtime($php_class_file_path);
		$time_key = 'Yii-CWebService-time-'.$providerClass.'.txt';
		if(file_exists($wsdl_cache_dir.$time_key))
		{
			$l_time = file_get_contents($wsdl_cache_dir.$time_key);
			if($last_up_time > $l_time)
			{
				file_put_contents($wsdl_cache_dir.$time_key , $last_up_time);
				file_put_contents($wsdl_cache_dir.$key , $wsdl);
				return $wsdl;
			}
			else
			{
				return file_get_contents($wsdl_cache_dir.$key);
			}
		}
		else
		{
			file_put_contents($wsdl_cache_dir.$time_key , $last_up_time);
			file_put_contents($wsdl_cache_dir.$key , $wsdl);
			return $wsdl;
		}
	}
将每次更新的接口php文件的更新时间做一个缓存,更新php文件的同时更新接口的wsdl文件。



阅读(117) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~