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;
}
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);
Hopefully this helps!
DigitalOcean Support