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;
}
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.