Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 396
Bobj-C Avatar asked Jan 19 '23 21:01

Bobj-C


2 Answers

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

To silence the warning make the following change:

@socket_close($apns);
like image 164
Jonathan Schläpfer Avatar answered Jan 29 '23 12:01

Jonathan Schläpfer


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.

like image 27
Marc B Avatar answered Jan 29 '23 12:01

Marc B