开发者

send push notification form my server PHP

开发者 https://www.devze.com 2023-03-01 00:44 出处:网络
I\'am trying to send push notification from my localhost to my iDevices all work properly but in the PHP error log I got the warning below Why ?

I'am trying to send push notification from my localhost to my iDevices all work properly but in the PHP error log I got the warning below Why ?

NOTE: I receive the Push on all Devices

THE WARNING:

PHP Warning:  socket_close():开发者_如何学Go supplied resource is not a valid Socket resource in /Applications/MAMP/htdocs/Push/SendPush.php on line xxx

Some of My Code:

//....
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
//...

socket_close($apns);
fclose($apns);


Most likely Apple is terminating the connection after it receives your payload.

To silence the warning make the following change:

@socket_close($apns);


stream_socket_client() returns false if there was an error. You should explicitly test for it:

$apns = stream_socket_client(...);
if ($apns === FALSE) then
    die("Error while getting stream socket ($error): $errorString");
}

where $error/$errorString are the ones you've specified in the stream_socket_client() call.

0

精彩评论

暂无评论...
验证码 换一张
取 消