drzfnr0275 2019-03-16 06:42
浏览 53

卷曲超时卷曲并发送推送通知

I have some problems with push notification with php & android.

When I make new order with android app after it insert to database and before response to android app, I start a service whit bellow code:

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, "token=" . config('app.passwords.service_token'));
    curl_setopt($curl, CURLOPT_TIMEOUT, 1);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 1);
    curl_setopt($curl, CURLOPT_NOSIGNAL, 1);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
    $response = curl_exec($curl);
    curl_close($curl);

This code will send the push notification.

I have problem with curl timeout. In this code it is 1 second. In most cases, the request sent with curl takes more time and is not sent push as a result. If we increase the timeout value, the answer will be delayed to the android app and problems will be on the Android side.

What do you suggest? What should I do?

  • 写回答

1条回答 默认 最新

  • dst67283 2019-03-16 07:26
    关注

    I would suggest you increase the:

    CURLOPT_TIMEOUT > CURLOPT_CONNECTTIMEOUT
    

    because if your server's bandwidth usage is high or you are not on production server and your connection speed is very low, it might take a few seconds to connect and when the connection is successful then it will try to send the push, so yes

    评论

报告相同问题?