Php curl_exec die and exit script and show white screen

this is my code: when i try to connect to whm / cpanel to add a new account this problem comes up, but when i try to remove user from whm / cpanel it works fine. my problem is curl_exec line die and show me a blank white screen, there is no error on the page and curl_error was not returning any codes after curl_exec was not started at all.

thank you for your responses

$curl = curl_init();
# Create Curl Object
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
# Allow certs that do not match the domain
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
# Allow self-signed certs
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
# Return contents of transfer on curl_exec
$header[0] = "Authorization: WHM $cpanel_user:" . preg_replace("'(\r|\n)'", "", $whmhash);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 1800);
# Remove newlines from the hash
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
# Set curl header
curl_setopt($curl, CURLOPT_URL, $command);
# Set your URL
curl_setopt($curl, CURLOPT_FAILONERROR, FALSE);

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
if( ! $result = curl_exec($curl))

$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
# Execute Query, assign to $result
if ($result == false) {
    error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");



source to share

2 answers

The problem was nginx was not allowing the response to fall back to my code. by disabling nginx on the server that is running in proxy mode for apache which it solved.



You have to use curl_errno to check if there was an error with curl

Replace this

if( ! $result = curl_exec($curl))



$result = curl_exec($curl);
// Check for errors and display the error message
if($errno = curl_errno($curl)) {
    $error_message = curl_strerror($errno);
    trigger_error("cURL error ({$errno}):\n {$error_message}");



All Articles