We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How can I make curl to work in my local environment?

Hi, I am doing a simple GET request using curl but I can't make it work. I have curl installed and I was able to do some POST/GET requests to other sites so I know it's working.

class TestsController extends ControllerBase{
    public function curlAction{
        $this->view->disable();
        $this->response->setStatusCode(200,'OK');
        $this->response->setJsonContent(['content' => 'success']);
        $this->response->send();
    }

    public function sendAction(){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://localhost/tests/curl");
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        $output = curl_exec($ch);
        curl_close($ch);
        var_dump($output); //result is always false
    }

}

The curl action works when I am using cli CURL and when using POSTMAN, but no luck when trying the send action. Am I missing something?

--EDIT--

When I try to output curl error it says couldn't connect to host.



827
Accepted
answer

I got it working. Seems like my installation of curl used a different port. I configured it to the default and it worked.