简体   繁体   中英

send push notification form my server PHP

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(): 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM