分类: PHP
2013-01-16 15:45:54
如果服务器安装了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文件。