src/NBOS/http/Curl.php
public function execute()
	{
		// Set two default options, and merge any extra ones in
		if ( ! isset($this->options[CURLOPT_TIMEOUT]))
		{
			$this->options[CURLOPT_TIMEOUT] = 30;
		}
		if ( ! isset($this->options[CURLOPT_RETURNTRANSFER]))
		{
			$this->options[CURLOPT_RETURNTRANSFER] = TRUE;
		}
		if ( ! isset($this->options[CURLOPT_FAILONERROR]))
		{
			$this->options[CURLOPT_FAILONERROR] = TRUE;
		}

		// Only set follow location if not running securely
		if ( ! ini_get('safe_mode') && ! ini_get('open_basedir'))
		{
			// Ok, follow location is not set already so lets set it to true
			if ( ! isset($this->options[CURLOPT_FOLLOWLOCATION]))
			{
				$this->options[CURLOPT_FOLLOWLOCATION] = TRUE;
			}
		}

		if ( ! empty($this->headers))
		{
			$this->option(CURLOPT_HTTPHEADER, $this->headers);
		}

		$this->options();
        curl_setopt($this->session, CURLINFO_HEADER_OUT, true);
		curl_setopt($this->session, CURLOPT_HEADER, 1);

		// Execute the request & and hide all output
		$this->response = curl_exec($this->session);
		if($this->response !== false){
			$this->info = curl_getinfo($this->session);
			// Split header and body response
			//$header_size = curl_getinfo($this->session, CURLINFO_HEADER_SIZE);
			//$this->response_header = substr($this->response, 0, $header_size);
			//$this->response = substr($this->response, $header_size);
			list($this->response_header, $this->response) = explode("\r\n\r\n", $this->response);

			if(defined('CURL_DEBUG') && $this->log !== null){
				$this->log->addInfo($this->url, [
					"Request" => $this->info,
					"Response" => $this->response
				]);
			}
		}else{
			if(defined('CURL_DEBUG') && $this->log !== null){
				$this->log->addError("Server not responding!", ["URL" => $this->url], ["message" => "test"]);
			}
		}

		// Request failed
		if ($this->response === FALSE)
		{
			$errno = curl_errno($this->session);
			$error = curl_error($this->session);

			curl_close($this->session);
			$this->set_defaults();

			$this->error_code = $errno;
			$this->error_string = $error;

			return FALSE;
		}
		// Request successful
		else
		{
			curl_close($this->session);
			$this->last_response = $this->response;
			$this->last_response_header = $this->response_header;
            $this->last_info = $this->info;
			$this->set_defaults();
			return $this->last_response;
		}
	}
public function execute()
	{
		// Set two default options, and merge any extra ones in
		if ( ! isset($this->options[CURLOPT_TIMEOUT]))
		{
			$this->options[CURLOPT_TIMEOUT] = 30;
		}
		if ( ! isset($this->options[CURLOPT_RETURNTRANSFER]))
		{
			$this->options[CURLOPT_RETURNTRANSFER] = TRUE;
		}
		if ( ! isset($this->options[CURLOPT_FAILONERROR]))
		{
			$this->options[CURLOPT_FAILONERROR] = TRUE;
		}

		// Only set follow location if not running securely
		if ( ! ini_get('safe_mode') && ! ini_get('open_basedir'))
		{
			// Ok, follow location is not set already so lets set it to true
			if ( ! isset($this->options[CURLOPT_FOLLOWLOCATION]))
			{
				$this->options[CURLOPT_FOLLOWLOCATION] = TRUE;
			}
		}

		if ( ! empty($this->headers))
		{
			$this->option(CURLOPT_HTTPHEADER, $this->headers);
		}

		$this->options();
        curl_setopt($this->session, CURLINFO_HEADER_OUT, true);
		curl_setopt($this->session, CURLOPT_HEADER, 1);

		// Execute the request & and hide all output
		$this->response = curl_exec($this->session);
		if($this->response !== false){
			$this->info = curl_getinfo($this->session);
			// Split header and body response
			//$header_size = curl_getinfo($this->session, CURLINFO_HEADER_SIZE);
			//$this->response_header = substr($this->response, 0, $header_size);
			//$this->response = substr($this->response, $header_size);
			list($this->response_header, $this->response) = explode("\r\n\r\n", $this->response);

			if(defined('CURL_DEBUG') && $this->log !== null){
				$this->log->addInfo($this->url, [
					"Request" => $this->info,
					"Response" => $this->response
				]);
			}
		}else{
			if(defined('CURL_DEBUG') && $this->log !== null){
				$this->log->addError("Server not responding!", ["URL" => $this->url], ["message" => "test"]);
			}
		}

		// Request failed
		if ($this->response === FALSE)
		{
			$errno = curl_errno($this->session);
			$error = curl_error($this->session);

			curl_close($this->session);
			$this->set_defaults();

			$this->error_code = $errno;
			$this->error_string = $error;

			return FALSE;
		}
		// Request successful
		else
		{
			curl_close($this->session);
			$this->last_response = $this->response;
			$this->last_response_header = $this->response_header;
            $this->last_info = $this->info;
			$this->set_defaults();
			return $this->last_response;
		}
	}
public function execute ( ) { // Set two default options, and merge any extra ones in if ( ! isset ( $ this -> options [ CURLOPT_TIMEOUT ] ) ) { $ this -> options [ CURLOPT_TIMEOUT ] = 30 ; } if ( ! isset ( $ this -> options [ CURLOPT_RETURNTRANSFER ] ) ) { $ this -> options [ CURLOPT_RETURNTRANSFER ] = TRUE ; } if ( ! isset ( $ this -> options [ CURLOPT_FAILONERROR ] ) ) { $ this -> options [ CURLOPT_FAILONERROR ] = TRUE ; } // Only set follow location if not running securely if ( ! ini_get ( 'safe_mode' ) && ! ini_get ( 'open_basedir' ) ) { // Ok, follow location is not set already so lets set it to true if ( ! isset ( $ this -> options [ CURLOPT_FOLLOWLOCATION ] ) ) { $ this -> options [ CURLOPT_FOLLOWLOCATION ] = TRUE ; } } if ( ! empty ( $ this -> headers ) ) { $ this -> option ( CURLOPT_HTTPHEADER , $ this -> headers ) ; } $ this -> options ( ) ; curl_setopt ( $ this -> session , CURLINFO_HEADER_OUT , true ) ; curl_setopt ( $ this -> session , CURLOPT_HEADER , 1 ) ; // Execute the request & and hide all output $ this -> response = curl_exec ( $ this -> session ) ; if ( $ this -> response !== false ) { $ this -> info = curl_getinfo ( $ this -> session ) ; // Split header and body response //$header_size = curl_getinfo($this->session, CURLINFO_HEADER_SIZE); //$this->response_header = substr($this->response, 0, $header_size); //$this->response = substr($this->response, $header_size); list ( $ this -> response_header , $ this -> response ) = explode ( "\r\n\r\n" , $ this -> response ) ; if ( defined ( 'CURL_DEBUG' ) && $ this -> log !== null ) { $ this -> log -> addInfo ( $ this -> url , [ "Request" => $ this -> info , "Response" => $ this -> response ] ) ; } } else { if ( defined ( 'CURL_DEBUG' ) && $ this -> log !== null ) { $ this -> log -> addError ( "Server not responding!" , [ "URL" => $ this -> url ] , [ "message" => "test" ] ) ; } } // Request failed if ( $ this -> response === FALSE ) { $ errno = curl_errno ( $ this -> session ) ; $ error = curl_error ( $ this -> session ) ; curl_close ( $ this -> session ) ; $ this -> set_defaults ( ) ; $ this -> error_code = $ errno ; $ this -> error_string = $ error ; return FALSE ; } // Request successful else { curl_close ( $ this -> session ) ; $ this -> last_response = $ this -> response ; $ this -> last_response_header = $ this -> response_header ; $ this -> last_info = $ this -> info ; $ this -> set_defaults ( ) ; return $ this -> last_response ; } }
End a session and return the results
End a session and return the results