Question

How to hide result of reboot curl method

i was made a script php to reboot a droplets. But when run, this script also display the result of this script. How to hide?

public function rebootDroplet($id) {
		$this->id = $id;
		$this->data = array("type" => "reboot");
		$this->data_string = json_encode($this->data);

		$this->ch = curl_init('https://api.digitalocean.com/v2/droplets/'.$this->id.'/actions');
		curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "POST");
		curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->data_string);
		curl_setopt($this->ch, CURLOPT_HTTPHEADER, array(
		    'Authorization: Bearer '.$this->api,
		    'Content-Type: application/json',
		    'Content-Length: ' . strlen($this->data_string))
		);

		$this->result = curl_exec($this->ch);
		return $this->result = true;
	}
Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi!

Based on the code you have provided here, the option you need to set is CURLOPT_RETURNTRANSFER. This will prevent curl from displaying the result it is returned. If you use the following configuration, do you receive the desired output?

public function rebootDroplet($id) { $this->id = $id; $this->data = array(“type” => “reboot”); $this->data_string = json_encode($this->data);

    $this->ch = curl_init('https://api.digitalocean.com/v2/droplets/'.$this->id.'/actions');
    curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->data_string);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($this->ch, CURLOPT_HTTPHEADER, array(
        'Authorization: Bearer '.$this->api,
        'Content-Type: application/json',
        'Content-Length: ' . strlen($this->data_string))
    );

    $this->result = curl_exec($this->ch);
    return $this->result = true;
}

Hopefully this helps!

DigitalOcean Support