| Line 21... |
Line 21... |
| 21 |
private $calls = array(); // multidimensional array that holds individual calls and data
|
21 |
private $calls = array(); // multidimensional array that holds individual calls and data
|
| 22 |
private $curl_parent; // the curl multi handle resource
|
22 |
private $curl_parent; // the curl multi handle resource
|
| 23 |
|
23 |
|
| 24 |
function __construct()
|
24 |
function __construct()
|
| 25 |
{
|
25 |
{
|
| - |
|
26 |
|
| 26 |
$this->_ci = & get_instance();
|
27 |
$this->_ci = & get_instance();
|
| 27 |
log_message('debug', 'Mcurl Class Initialized');
|
28 |
log_message('debug', 'Mcurl Class Initialized');
|
| 28 |
if (!$this->is_enabled())
|
29 |
if (!$this->is_enabled())
|
| 29 |
{
|
30 |
{
|
| 30 |
log_message('error', 'Mcurl Class - PHP was not built with cURL enabled. Rebuild PHP with --with-curl to use cURL.');
|
31 |
log_message('error', 'Mcurl Class - PHP was not built with cURL enabled. Rebuild PHP with --with-curl to use cURL.');
|
| Line 38... |
Line 39... |
| 38 |
// check to see if necessary function exists
|
39 |
// check to see if necessary function exists
|
| 39 |
function is_enabled()
|
40 |
function is_enabled()
|
| 40 |
{
|
41 |
{
|
| 41 |
return function_exists('curl_multi_init');
|
42 |
return function_exists('curl_multi_init');
|
| 42 |
}
|
43 |
}
|
| 43 |
|
- |
|
| 44 |
// method to add curl requests to the multi request queue
|
44 |
// method to add curl requests to the multi request queue
|
| 45 |
function add_call($key=null, $method, $url, $params = array(), $options = array())
|
45 |
function add_call($key=null, $method, $url, $params = array(), $options = array())
|
| 46 |
{
|
46 |
{
|
| 47 |
//echo 'hello';
|
47 |
//echo 'hello';
|
| 48 |
if (is_null($key))
|
48 |
if (is_null($key))
|
| Line 144... |
Line 144... |
| 144 |
foreach ($this->calls as $key => $call)
|
144 |
foreach ($this->calls as $key => $call)
|
| 145 |
{
|
145 |
{
|
| 146 |
$error = curl_error($this->calls[$key]["curl"]);
|
146 |
$error = curl_error($this->calls[$key]["curl"]);
|
| 147 |
if (!empty($error))
|
147 |
if (!empty($error))
|
| 148 |
{
|
148 |
{
|
| 149 |
if($key != 'recommended_accessories'){
|
149 |
if($key != 'tracking' && $key != 'recommended_accessories'){
|
| 150 |
$this->calls[$key]["error"] = $error;
|
150 |
$this->calls[$key]["error"] = $error;
|
| - |
|
151 |
$this->_ci->session->set_userdata('errorurl',$url);
|
| 151 |
$errmsg ='<h3>OH SNAP!!!! :</h3><p>Something is not right. <br/><h1>But Relax</h1> <br/>We are working hard on it. </p>';
|
152 |
//$errmsg ='<h3>OH SNAP!!!! :</h3><p>Something is not right. <br/><h1>But Relax</h1> <br/>We are working hard on it. </p>';
|
| - |
|
153 |
$msg = '
|
| - |
|
154 |
API for '.$key.' is not working.
|
| - |
|
155 |
|
| - |
|
156 |
url of API Failed ===> '.$this->calls[$key]['url'].'
|
| - |
|
157 |
|
| - |
|
158 |
Access modifier is Public.
|
| - |
|
159 |
|
| - |
|
160 |
Error is ====> '.$this->calls[$key]["error"].'';
|
| 152 |
//$this->write_log_send_mail('error',$msg);
|
161 |
$this->write_log_send_mail('error',$msg);
|
| 153 |
//$this->session->set_flashdata('errormsg',$errmsg);
|
162 |
//$this->session->set_flashdata('errormsg',$errmsg);
|
| 154 |
//redirect(base_url().'error_page/index');
|
163 |
redirect(base_url().'error_page/index');
|
| 155 |
//exit();
|
164 |
exit();
|
| 156 |
}
|
165 |
}
|
| 157 |
}
|
166 |
}
|
| 158 |
$this->calls[$key]["response"] = curl_multi_getcontent($this->calls[$key]["curl"]);
|
167 |
$this->calls[$key]["response"] = curl_multi_getcontent($this->calls[$key]["curl"]);
|
| 159 |
//print_r($this->calls[$key]["response"]);
|
- |
|
| 160 |
$http_status = curl_getinfo($this->calls[$key]["curl"], CURLINFO_HTTP_CODE);
|
168 |
$http_status = curl_getinfo($this->calls[$key]["curl"], CURLINFO_HTTP_CODE);
|
| 161 |
if($key != 'tracking' && $key != 'recommended_accessories'){
|
169 |
if($key != 'tracking' && $key != 'recommended_accessories'){
|
| 162 |
if($http_status != 200) {
|
170 |
if($http_status != 200) {
|
| 163 |
$url = 'http://www.saholic.com/'.uri_string();
|
171 |
$url = 'http://www.saholic.com/'.uri_string();
|
| 164 |
$this->_ci->session->set_userdata('errorurl',$url);
|
172 |
$this->_ci->session->set_userdata('errorurl',$url);
|
| - |
|
173 |
$msg = '
|
| - |
|
174 |
API for '.$key.' is not working.
|
| - |
|
175 |
|
| - |
|
176 |
url of API Failed ===> '.$this->calls[$key]['url'].'
|
| - |
|
177 |
|
| - |
|
178 |
Access modifier is Public.
|
| - |
|
179 |
|
| - |
|
180 |
Error is ====> '.$this->calls[$key]["error"].'';
|
| - |
|
181 |
$this->write_log_send_mail('error',$msg);
|
| 165 |
redirect(base_url().'error_page/index');
|
182 |
redirect(base_url().'error_page/index');
|
| 166 |
exit();
|
183 |
exit();
|
| 167 |
}
|
184 |
}
|
| 168 |
}
|
185 |
}
|
| 169 |
curl_multi_remove_handle($this->curl_parent,$this->calls[$key]["curl"]);
|
186 |
curl_multi_remove_handle($this->curl_parent,$this->calls[$key]["curl"]);
|
| Line 187... |
Line 204... |
| 187 |
}
|
204 |
}
|
| 188 |
echo '<textarea cols="100" rows="10">'.htmlentities($call["response"])."</textarea><hr>";
|
205 |
echo '<textarea cols="100" rows="10">'.htmlentities($call["response"])."</textarea><hr>";
|
| 189 |
}
|
206 |
}
|
| 190 |
}
|
207 |
}
|
| 191 |
|
208 |
|
| - |
|
209 |
function write_log_send_mail($level = 'error', $msg, $php_error = FALSE){
|
| - |
|
210 |
$params = $this->_ci->config->item('email_params');
|
| - |
|
211 |
$this->_ci->load->library('email',$params);
|
| - |
|
212 |
$this->_ci->email->set_newline("\r\n");
|
| - |
|
213 |
$this->_ci->email->from('mobile@letsgomo.com', 'NO-REPLY');
|
| - |
|
214 |
$list = $this->_ci->config->item('email_list');
|
| - |
|
215 |
$this->_ci->email->to($list);
|
| - |
|
216 |
$this->_ci->email->cc('yashmeet@letsgomo.com');
|
| - |
|
217 |
$this->_ci->email->subject('The API failed on '.date('m/d/Y'));
|
| - |
|
218 |
$this->_ci->email->message('The API failed at '.date('m/d/Y h:i:s a', time()).' ------> '.$msg);
|
| - |
|
219 |
//send the email
|
| - |
|
220 |
$this->_ci->email->send();
|
| - |
|
221 |
}
|
| - |
|
222 |
|
| 192 |
}
|
223 |
}
|
| 193 |
|
224 |
|
| 194 |
/* End of file mcurl.php */
|
225 |
/* End of file mcurl.php */
|
| 195 |
/* Location: ./application/libraries/mcurl.php */
|
226 |
/* Location: ./application/libraries/mcurl.php */
|
| 196 |
|
227 |
|