B
B
b4rret2019-04-16 12:21:00
PHP
b4rret, 2019-04-16 12:21:00

Why does an OpenSSL error occur when using curl?

I send notifications using multi curl and firebase cloud messaging service. All messages with different data, so one message, specifying only tokens, cannot be sent. (Probably not the best solution) When sending about 400 messages, everything is OK, if more (eg 800) then an OpenSSL error occurs. Ubuntu 18.04 system, updated openssl to 1.1.1b, did not help. At the same time, I checked it on another server with the same OS versions, openssl, curl, php, everything worked there.
OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to fcm.googleapis.com:443

$connectionArray = [];
$cmh = curl_multi_init();

$headers = [
    'Authorization:key = fcm.serverKey',
    'Content-Type: application/json'
];

foreach($notifyArr as $notify) {
    $fields = [
        'registration_ids' => explode(',', $notify->user_token),
        'priority' => 'high',
        'content_available' => true,
        'notification' => [
            'title' => $notify->title,
            'body' => $notify->text,
            'sound' => 'default'
        ]
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'fcm.url');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $connectionArray[] = $ch;
    curl_multi_add_handle($cmh, $ch);
}

$running = null;
do {
    curl_multi_exec($cmh, $running);
} while($running > 0);

foreach($connectionArray as $ch) {
    $info = curl_getinfo($ch);
    if( $info['total_time'] <= 0 || !is_numeric($info['total_time']) ) {
        $errors = true;
        continue;
    }
    curl_multi_remove_handle($cmh, $ch);
}
curl_multi_close($cmh);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
b4rret, 2019-04-17
@b4rret

In general, for those who are interested, I broke $notifyArr into arrays of 100 elements, the error disappeared

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question