Created
October 29, 2012 08:01
-
-
Save jigar/3972260 to your computer and use it in GitHub Desktop.
curl lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Curl Helper | |
* @author Jigar Vyas | |
*/ | |
class Curl { | |
private $ch = null; | |
private $result = null; | |
private $params = null; | |
public function __construct($params = null) { | |
$this->ch = curl_init(); | |
$this->params = $params; | |
if (!empty($this->params['follow_location'])) { | |
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, $this->params['follow_location']); | |
} | |
if (!empty($this->params['return_transfer'])) { | |
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, $this->params['return_transfer']); | |
} else { | |
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, TRUE); | |
} | |
/* | |
if (!strpos($this->params['url'], "https")) { | |
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0); | |
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false); | |
} | |
*/ | |
} | |
public function get($url) { | |
curl_setopt($this->ch, CURLOPT_URL, $url); | |
return $this->_result(); | |
} | |
public function post($params) { | |
curl_setopt($this->ch, CURLOPT_URL, $params['url']); | |
curl_setopt($this->ch, CURLOPT_POST, 1); | |
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $params['fields_data']); | |
return $this->_result(); | |
} | |
public function put() { | |
$put_string = stripslashes($this->params['fields_data']); | |
// echo "Path: ".sys_get_temp_dir()."\n"; | |
$put_data = tmpfile(); | |
// echo "PUT DATA: "; var_dump($put_data); | |
fwrite($put_data, $put_string); | |
fseek($put_data, 0); | |
curl_setopt($this->ch, CURLOPT_BINARYTRANSFER, true); | |
curl_setopt($this->ch, CURLOPT_PUT, true); | |
curl_setopt($this->ch, CURLOPT_INFILE, $put_data); | |
curl_setopt($this->ch, CURLOPT_INFILESIZE, strlen($put_string)); | |
fclose($put_data); | |
return $this->_result(); | |
} | |
private function _result() { | |
$this->result = curl_exec($this->ch); | |
return $this->result; | |
} | |
public function __destruct() { | |
curl_close($this->ch); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! I have something similar: https://github.com/phpish/http check