/** * Connects with the OAuth database * * @return array is NOK | nothing if OK */ private function _connect_oauth() { try { $db = $this->_db['oauth']; $this->_oauthdb = new \PDO('mysql:host=' . $db['host'] . ';dbname=' . $db['database'], $db['username'], $db['password']); } catch (\Exception $e) { $e = new APIException('An error ocurred while connecting with the database.'); $e->to_json(); } }
/** * Connects with the remote services. Sets a timeout for connecting the service and a timeout for receiving the data. * * @param String $url The url to retrieve, it must return a json. * @return String json returned by remote service */ private function &_curl_get_data($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_TIMEOUT, 14); $data = curl_exec($ch); if (curl_errno($ch)) { $e = new APIException('CLIR request timeout.'); $e->to_json(); } curl_close($ch); return $data; }
/** * Makes an HTTP through curl as POST * * @param string $url The URL for making the request to * @param array $post_data The data to be passed through as POST payload * @return string The requested URL content */ private function _curl_request($url, &$post_data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query($post_data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_TIMEOUT, 15); #curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $post_data ) ); $data = curl_exec($ch); if (curl_errno($ch) > 0) { $e = new APIException('Search request timeout.'); $e->to_json(); die; } curl_close($ch); return $data; }
private function _curl_post_data(&$url, &$info) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_TIMEOUT, 14); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($info)); $data = curl_exec($ch); if (curl_errno($ch)) { $e = new APIException('CLIR request timeout.'); $e->to_json(); } curl_close($ch); return $data; }