php – OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 104-ThrowExceptions

Exception or error:

I am posing order-data on ssl means (https) based api via curl, But it return OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 104 message.

Here is my test code as per client required json:

$apiKey = "xxxxxx-xxxxxx-xxxxx-xxxxxx-xxxxxx";
$privatekey = "xxxxxx-xxxxxx-xxxxx-xxxxxx-xxxxxx";
$timestamp = date('Y-m-d H:i:s'); // (for example: 2016-07-19 14:05:55)

$signature = hash_hmac('sha1', $timestamp, $apiKey);
$signature = hash_hmac('sha1', $privatekey, $signature);

$postURL = "https://www.compu-cover.com/intelligent-rewards/orders/?OrderNo=123";

$orderInfo['Order'] = array(
        "apiKey" => $apiKey,
        "privatekey" => $privatekey,
        "Signature" => $signature,
        "Timestamp" => $timestamp,
        "Firstname" => "Ajay",
        "Surname" => "Sharma",
        "EmailAddress" => "ajay@yopmail.com",
        "DaytimeTel" => "0141798526",
        "EveningTel" => "0141798526",
        "MobileTel" => "9887654321",
        "Address1" => "A-5",
        "Address2" => "Jhalana",
        "Address3" => "Jaipur",
        "Address4" => "Rajasthan",
        "County" => "India",
        "Postcode" => "302019", 
        "Cover" => "ADTBL",
        "Scheme" => 2, 
        "Premium" => 5,
        "EquipmentQty" => 1,
        "EquipmentType1" => "Smartphone",
        "EquipmentMake1" => "Moto",
        "EquipmentModel1" => "Moto G",
        "EquipmentPrice1" => 100
    );

$params = json_encode($orderInfo);

$session = curl_init($postURL);

curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $params);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, true); 

$response = curl_exec($session);

if (FALSE === $response) {
    var_dump(curl_error($session));
    var_dump(curl_errno($session));
}

curl_close($session);
$response = json_decode($response);

var_dump($response);

How to find reason for the failure? What could be the reason for failure? kindly provide your suggestions.

How to solve:

I’ve received this error, and gotten around it simply by waiting a half hour and trying again.

Answer:

There are probably many reasons you might get this.

For me, I got this because I was using curl and the web site I was accessing didn’t like curl being used. I fixed this with:

curl -A "Mozilla Chrome Safari" someserver.com/somepage.html

This tells curl to say to the server, ‘hey I’m a browser’. You can use your favourite browser to get a nicer newer string, go to the browser developer console typically under ‘network’ you can see individual request items and there you can get the string your current browser sends as the ‘user-agent’.

The reason why a website would do this is your typical customer doesn’t use curl. Best case a curl will be a bot using up server resource, worst case it’s an evil hacker.

Answer:

I also realized was missing post data information. After doing so everything worked as expected

Answer:

I had same issue.

OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 104

I guessed the error was regarded openssl or etc.
But, it was not.

In my case, one of POST parameters was wrong value. (something like OTP code)
And I resolved it finally.

Leave a Reply

Your email address will not be published. Required fields are marked *