我正在尝试执行,但没有任何结果。尽管调用了转储功能。有没有人注意到我做的任何遗漏部分或错误?可能是什么原因?提前谢谢!
在我的备份类中,我执行Curl并将其写入外部文件
class Backup {
private $url;
private $handler;
private $file;
private $timeout;
private $data;
private $write;
private $status;
private $auth_api;
public function setAuth($key) {
$this->auth_api = $key;
}
public function __construct($timeout = 5000) {
$this->timeout = $timeout;
}
public function init($url, $dir) {
$this->file = fopen($dir, "w") or die("cant find file location");
$this->url = $url;
$this->handler = curl_init();
curl_setopt($this->handler, CURLOPT_URL, $this->url);
curl_setopt($this->handler, CURLOPT_FILE, $this->file);
curl_setopt($this->handler, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->handler, CURLOPT_CONNECTTIMEOUT, $this->timeout);
curl_setopt($this->handler, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($this->handler, CURLOPT_FAILONERROR, true);
curl_setopt($this->handler, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($this->handler, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->handler, CURLOPT_USERPWD, $this->auth_api);
curl_setopt($this->handler, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
}
public function execute() {
$this->data = curl_exec($this->handler);
$error = curl_error($this->handler);
$result = array('header' => '', 'body' => '', 'curl_error' => '','http_code' => '');
if($error != "") {
$result['curl_error'] = $error;
return $result;
}
$header_size = curl_getinfo($this->handler, CURLINFO_HEADER_SIZE);
$result['header'] = curl_getinfo($this->data, 0, $header_size);
$result['body'] = curl_getinfo($this->data, $header_size);
$result['http_code'] = curl_getinfo($this->handler, CURLINFO_HTTP_CODE);
$result['last_url'] = curl_getinfo($this->handler, CURLINFO_EFFECTIVE_URL);
return $result;
}
public function writeTofile() {
$this->write = fwrite($this->file, $this->data);
return $this;
}
function dump ($val, $exit = true, $return = false )
{
$output = "<pre>" . print_r( $val, true ) . "<pre>";
if($return) return $output;
echo $output;
if($exit) exit;
}
}
$curl = new Backup();
$curl->setAuth('xxxxxxxx.xxxxxxxxxxxxxxxxxxxx');
$curl->init('https://app.asana.com/api/1.0/users/me', 'backup/'.date('Ymd').'/me.json');
$curl->execute();
$result = $curl->writeTofile();
$curl->dump($result);
?>