Php XMLRPC中的fopen需要返回错误not die
因此,我在Zend PHP中开发了一个XMLRPC,并尝试返回错误消息,而不是使用die() 以下是我所拥有的:Php XMLRPC中的fopen需要返回错误not die,php,logic,fopen,Php,Logic,Fopen,因此,我在Zend PHP中开发了一个XMLRPC,并尝试返回错误消息,而不是使用die() 以下是我所拥有的: $this->fh = fopen($this->log_file, 'a') or die("Can't open log file: ".$this->log_file); 这样的事情可能吗?(伪代码) 可能就在我鼻子底下,我猜只是在放个脑屁 解决方案: 对于XMLRPC进程,E_警告将终止/崩溃该进程。使用XMLRPC 响应警告消息使用函数前面的@
$this->fh = fopen($this->log_file, 'a')
or die("Can't open log file: ".$this->log_file);
这样的事情可能吗?(伪代码)
可能就在我鼻子底下,我猜只是在放个脑屁
解决方案:
对于XMLRPC进程,E_警告将终止/崩溃该进程。使用XMLRPC
响应警告消息使用函数前面的@符号来抑制
警告#错误/例外
// If the open fails,
// an error of level E_WARNING is generated.
// You may use @ to suppress this warning.
if(!($this->fh = @fopen($this->log_file, 'a'))) {
return "Can't open log file: ".$this->log_file;
}
在推测时使用return没有错,但是您需要确保在调用函数中处理这种行为 要确定fopen是否成功,您可以根据示例内联比较返回值,或者在文件句柄上使用is_资源函数 返回: :
谢谢,我知道这是我没有尝试过的,我还需要添加@符号来抑制E_警告一个更好的解决方案是首先对文件调用is_writable();我只是想回答你的具体问题。
// If the open fails,
// an error of level E_WARNING is generated.
// You may use @ to suppress this warning.
if(!($this->fh = @fopen($this->log_file, 'a'))) {
return "Can't open log file: ".$this->log_file;
}
if(!($this->fh = fopen($this->log_file, 'a'))) {
return "Can't open log file: ".$this->log_file;
}
// if you get here, $this->fh contains a file handle
if($this->fh = fopen($this->log_file, 'a')) {
// Everything is fine.
}
else {
// Error condition...
return "Can't open log file: ".$this->log_file;
}
$this->fh = fopen($this->log_file, 'a');
if(is_resource($this->fh)) {
// Everything is fine...
}
else {
// Error condition...
return "Can't open log file: ".$this->log_file;
}